From: Thomas Veerman Date: Thu, 15 Jul 2010 12:48:15 +0000 (+0000) Subject: Update header files to support UNIX Domain Sockets. Contributed by Thomas Cort X-Git-Tag: v3.1.8~232 X-Git-Url: http://zhaoyanbai.com/repos/%22../static/icons/man.3.ps?a=commitdiff_plain;h=17a0731f2872a13d332e950420e76a3ff9409f50;p=minix.git Update header files to support UNIX Domain Sockets. Contributed by Thomas Cort --- diff --git a/include/limits.h b/include/limits.h index d2742005e..405a9ac97 100644 --- a/include/limits.h +++ b/include/limits.h @@ -102,7 +102,7 @@ #define MAX_INPUT 255 /* size of the type-ahead buffer */ #define NAME_MAX DIRSIZ /* # chars in a file name */ #define PATH_MAX __MINIX_PATH_MAX /* # chars in a path name */ -#define PIPE_BUF 7168 /* # bytes in atomic write to a pipe */ +#define PIPE_BUF 32768 /* # bytes in atomic write to a pipe */ #define STREAM_MAX 20 /* must be the same as FOPEN_MAX in stdio.h */ #define TZNAME_MAX 3 /* maximum bytes in a time zone name is 3 */ #define SSIZE_MAX 32767 /* max defined byte count for read() */ diff --git a/include/minix/const.h b/include/minix/const.h index 0ecd1ef3e..ce4159e30 100644 --- a/include/minix/const.h +++ b/include/minix/const.h @@ -131,6 +131,7 @@ /* Flag bits for i_mode in the inode. */ #define I_TYPE 0170000 /* this field gives inode type */ +#define I_UNIX_SOCKET 0140000 /* unix domain socket */ #define I_SYMBOLIC_LINK 0120000 /* file is a symbolic link */ #define I_REGULAR 0100000 /* regular file, not dir or special */ #define I_BLOCK_SPECIAL 0060000 /* block special file */ diff --git a/include/minix/dmap.h b/include/minix/dmap.h index c35e44dc0..3b1cd8890 100644 --- a/include/minix/dmap.h +++ b/include/minix/dmap.h @@ -34,6 +34,7 @@ enum dev_style { STYLE_NDEV, STYLE_DEV, STYLE_DEVA, STYLE_TTY, STYLE_CTTY, #define LOG_MAJOR 15 /* 15 = /dev/klog (log driver) */ #define RANDOM_MAJOR 16 /* 16 = /dev/random (random driver) */ #define HELLO_MAJOR 17 /* 17 = /dev/hello (hello driver) */ +#define UDS_MAJOR 18 /* 18 = /dev/uds (pfs) */ /* Minor device numbers for memory driver. */ diff --git a/include/minix/vfsif.h b/include/minix/vfsif.h index 32149ec27..01f3d434d 100644 --- a/include/minix/vfsif.h +++ b/include/minix/vfsif.h @@ -117,5 +117,7 @@ typedef struct { #define NREQS 33 +#define IS_VFS_RQ(type) (((type) & ~0xff) == VFS_BASE) + #endif diff --git a/include/net/ioctl.h b/include/net/ioctl.h index de73b0f88..5c2b4980f 100644 --- a/include/net/ioctl.h +++ b/include/net/ioctl.h @@ -7,6 +7,7 @@ #define _NET__IOCTL_H #include +#include /* Network ioctls. */ #define NWIOSETHOPT _IOW('n', 16, struct nwio_ethopt) @@ -50,9 +51,29 @@ #define NWIOGUDPOPT _IOR('n', 65, struct nwio_udpopt) #define NWIOUDPPEEK _IOR('n', 66, struct udp_io_hdr) +#define NWIOGUDSFADDR _IOR('n', 67, struct sockaddr_un) /* recvfrom() */ +#define NWIOSUDSTADDR _IOW('n', 68, struct sockaddr_un) /* sendto() */ +#define NWIOSUDSADDR _IOW('n', 69, struct sockaddr_un) /* bind() */ +#define NWIOGUDSADDR _IOR('n', 70, struct sockaddr_un) /* getsockname() */ +#define NWIOGUDSPADDR _IOR('n', 71, struct sockaddr_un) /* getpeername() */ +#define NWIOSUDSTYPE _IOW('n', 72, int) /* socket() */ +#define NWIOSUDSBLOG _IOW('n', 73, int) /* listen() */ +#define NWIOSUDSCONN _IOW('n', 74, struct sockaddr_un) /* connect() */ +#define NWIOSUDSSHUT _IOW('n', 75, int) /* shutdown() */ +#define NWIOSUDSPAIR _IOW('n', 76, dev_t) /* socketpair() */ +#define NWIOSUDSACCEPT _IOW('n', 77, struct sockaddr_un) /* accept() */ + #define NWIOSPSIPOPT _IOW('n', 80, struct nwio_psipopt) #define NWIOGPSIPOPT _IOR('n', 81, struct nwio_psipopt) +/* setsockopt/setsockopt for unix domain sockets */ +#define NWIOGUDSSOTYPE _IOR('n', 90, int) /* SO_TYPE */ +#define NWIOGUDSPEERCRED _IOR('n', 91, struct ucred) /* SO_PEERCRED */ +#define NWIOGUDSSNDBUF _IOR('n', 92, size_t) /* SO_SNDBUF */ +#define NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */ +#define NWIOGUDSRCVBUF _IOR('n', 94, size_t) /* SO_RCVBUF */ +#define NWIOSUDSRCVBUF _IOW('n', 95, size_t) /* SO_RCVBUF */ + #endif /* _NET__IOCTL_H */ /* diff --git a/include/net/netlib.h b/include/net/netlib.h index b2a496410..fd6eade57 100644 --- a/include/net/netlib.h +++ b/include/net/netlib.h @@ -19,5 +19,6 @@ _PROTOTYPE (int rcmd, (char **ahost, int rport, const char *locuser, #define IP_DEVICE "/dev/ip" #define TCP_DEVICE "/dev/tcp" #define UDP_DEVICE "/dev/udp" +#define UDS_DEVICE "/dev/uds" #endif /* _NET__NETLIB_H_ */ diff --git a/include/sys/Makefile b/include/sys/Makefile index 37623982e..e53387b25 100644 --- a/include/sys/Makefile +++ b/include/sys/Makefile @@ -8,7 +8,7 @@ INCS= asynchio.h dir.h file.h ioc_cmos.h ioc_disk.h \ mount.h mtio.h param.h ptrace.h queue.h resource.h \ select.h sem.h shm.h sigcontext.h signal.h socket.h \ soundcard.h statfs.h statvfs.h stat.h svrctl.h timeb.h \ - time.h times.h types.h ucontext.h uio.h un.h utsname.h video.h vm.h \ - wait.h cdefs.h null.h + time.h times.h types.h ucontext.h ucred.h uio.h un.h \ + utsname.h video.h vm.h wait.h cdefs.h null.h .include diff --git a/include/sys/socket.h b/include/sys/socket.h index 119eea6e3..0e2ae8f3e 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -10,6 +10,8 @@ sys/socket.h */ #include +#include + /* Open Group Base Specifications Issue 6 (not complete) */ #include @@ -26,6 +28,9 @@ sys/socket.h #define SO_KEEPALIVE 0x0008 #define SO_TYPE 0x0010 /* get socket type, SOCK_STREAM or SOCK_DGRAM */ +#define SO_PASSCRED 0x0012 +#define SO_PEERCRED 0x0014 + #define SO_SNDBUF 0x1001 /* send buffer size */ #define SO_RCVBUF 0x1002 /* receive buffer size */ #define SO_ERROR 0x1007 /* get and clear error status */ @@ -48,6 +53,51 @@ struct sockaddr char sa_data[8]; /* Big enough for sockaddr_in */ }; +struct msghdr +{ + void *msg_name; + socklen_t msg_namelen; + struct iovec *msg_iov; + size_t msg_iovlen; + void *msg_control; + socklen_t msg_controllen; + int msg_flags; +}; + +struct cmsghdr +{ + socklen_t cmsg_len; + int cmsg_level; + int cmsg_type; +}; + +#define CMSG_FIRSTHDR(mhdr) \ + ( (mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL ) + +#define CMSG_ALIGN(len) \ + ( (len % sizeof(long) == 0) ? \ + len : \ + len + sizeof(long) - (len % sizeof(long)) ) + +#define CMSG_NXTHDR(mhdr, cmsg) \ + ( ((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ + (((unsigned char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) \ + + CMSG_ALIGN(sizeof(struct cmsghdr)) > \ + (unsigned char *)((mhdr)->msg_control) + \ + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((unsigned char *)(cmsg) + \ + CMSG_ALIGN((cmsg)->cmsg_len))) ) + +#define CMSG_DATA(cmsg) \ + ( (unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)) ) + +#define SCM_RIGHTS 0x01 +#define SCM_CREDENTIALS 0x02 +#define SCM_SECURITY 0x04 + _PROTOTYPE( int accept, (int _socket, struct sockaddr *_RESTRICT _address, socklen_t *_RESTRICT _address_len) ); @@ -58,6 +108,7 @@ _PROTOTYPE( int connect, (int _socket, const struct sockaddr *_address, _PROTOTYPE( int getpeername, (int _socket, struct sockaddr *_RESTRICT _address, socklen_t *_RESTRICT _address_len) ); +_PROTOTYPE( int getpeereid, (int _socket, uid_t *_euid, gid_t *_egid) ); _PROTOTYPE( int getsockname, (int _socket, struct sockaddr *_RESTRICT _address, socklen_t *_RESTRICT _address_len) ); @@ -71,13 +122,19 @@ _PROTOTYPE( ssize_t recv, (int _socket, void *_buffer, size_t _length, _PROTOTYPE( ssize_t recvfrom, (int _socket, void *_RESTRICT _buffer, size_t _length, int _flags, struct sockaddr *_RESTRICT _address, socklen_t *_RESTRICT _address_len) ); +_PROTOTYPE( ssize_t recvmsg, (int _socket, struct msghdr *_msg, + int _flags) ); _PROTOTYPE( ssize_t send, (int _socket, const void *_buffer, size_t _length, int _flags) ); +_PROTOTYPE( ssize_t sendmsg, (int _socket, const struct msghdr *_msg, + int _flags) ); _PROTOTYPE( ssize_t sendto, (int _socket, const void *_message, size_t _length, int _flags, const struct sockaddr *_dest_addr, socklen_t _dest_len) ); _PROTOTYPE( int shutdown, (int _socket, int _how) ); _PROTOTYPE( int socket, (int _domain, int _type, int _protocol) ); +_PROTOTYPE( int socketpair, (int _domain, int _type, int _protocol, + int _sv[2]) ); /* The following constants are often used in applications, but are not defined * by POSIX. @@ -85,6 +142,8 @@ _PROTOTYPE( int socket, (int _domain, int _type, int _protocol) ); #define PF_INET AF_INET #define PF_INET6 AF_INET6 #define PF_UNIX AF_UNIX +#define PF_LOCAL PF_UNIX +#define PF_FILE PF_UNIX #define PF_UNSPEC AF_UNSPEC /* based on http://tools.ietf.org/html/rfc2553 */ diff --git a/include/sys/ucred.h b/include/sys/ucred.h new file mode 100644 index 000000000..c88422d02 --- /dev/null +++ b/include/sys/ucred.h @@ -0,0 +1,11 @@ +#ifndef __SYS_UCRED_H +#define __SYS_UCRED_H + +struct ucred +{ + pid_t pid; + uid_t uid; + gid_t gid; +}; + +#endif diff --git a/include/sys/un.h b/include/sys/un.h index 902364f12..707316b6b 100644 --- a/include/sys/un.h +++ b/include/sys/un.h @@ -1,8 +1,7 @@ -/* -sys/un.h -*/ +#ifndef SYS_UN_H +#define SYS_UN_H -/* Open Group Base Specifications Issue 6 */ +#include #ifndef _SA_FAMILY_T #define _SA_FAMILY_T @@ -10,10 +9,23 @@ sys/un.h typedef uint8_t sa_family_t; #endif /* _SA_FAMILY_T */ +#define UNIX_PATH_MAX 127 + struct sockaddr_un { sa_family_t sun_family; - char sun_path[127]; + char sun_path[UNIX_PATH_MAX]; }; -/* Note: UNIX domain sockets are not implemented! */ +#include + +/* Compute the actual length of a struct sockaddr_un pointed + * to by 'unp'. sun_path must be NULL terminated. Length does + * not include the NULL byte. This is not a POSIX standard + * definition, but BSD and Linux have it, so it is here for + * compatibility. + */ +#define SUN_LEN(unp) \ +((size_t)((sizeof(*(unp)) - sizeof((unp)->sun_path)) + strlen((unp)->sun_path))) + +#endif diff --git a/include/unistd.h b/include/unistd.h index c8fbf9913..422e6d300 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -7,6 +7,8 @@ #include #endif +#include + /* Values used by access(). POSIX Table 2-8. */ #define F_OK 0 /* test if file exists */ #define X_OK 1 /* test if file is executable */ @@ -213,6 +215,7 @@ _PROTOTYPE(int getdma, (endpoint_t *procp, phys_bytes *basep, _PROTOTYPE( pid_t getnpid, (endpoint_t proc_ep) ); _PROTOTYPE( uid_t getnuid, (endpoint_t proc_ep) ); _PROTOTYPE( gid_t getngid, (endpoint_t proc_ep) ); +_PROTOTYPE( int getnucred, (endpoint_t proc_ep, struct ucred *ucred) ); #endif