]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/utils/sockutils.h
dc5d811eef40d85db4807a53fc44cae968a273dc
[keystone-rtos/netapi.git] / ti / runtime / netapi / utils / sockutils.h
1 /*
2  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *    Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *    Neither the name of Texas Instruments Incorporated nor the names of
18  *    its contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33 */
35 #ifndef __SOCKUTILS_H__
36 #define __SOCKUTILS_H__
38 #include <sys/socket.h>
39 #include <sys/un.h>
41 #ifndef UNIX_PATH_MAX
42 #define UNIX_PATH_MAX 108
43 #endif
46 typedef enum {
47         sock_name_e,
48         sock_addr_e
49 } sock_name_type;
51 typedef struct {
52         sock_name_type type;
53         union sock {
54                 char *name;
55                 struct sockaddr_un *addr;
56         } s;
57 } sock_name_t;
59 #define sock_h void *
61 sock_h sock_open (sock_name_t *sock_name);
63 int sock_close (sock_h handle);
65 int sock_send (sock_h handle, const char *data, int length,
66                         sock_name_t *to);
68 /* Returns: 1 => success (external FD), 0 => success, -1 => error, -2 => timeout */
69 int sock_wait (sock_h handle, int *size, struct timeval *timeout, int extern_fd);
71 int sock_recv (sock_h handle, char *data, int length, sock_name_t *from);
73 #endif