Professional Documents
Culture Documents
1socket Programming
1socket Programming
1socket Programming
One of the two processes, the client, connects to the other process, the
server, typically to make a request for information.
#include <sys/socket.h>
int socketpair(int domain, int type, int protocol, int
sockfds[2]);
#include <sys/socket.h>
#include <sys/un.h>
struct msghdr {
void * msg_name; /* optional address */
unsigned int msg_namelen; /* size of msg_name */
struct iovec * msg_iov; /* scatter/gather array */
unsigned int msg_iovlen; /* number of elements in msg_iov */
void * msg_control; /* ancillary data */
unsigned int msg_controllen; /* ancillary data buffer len */
int msg_flags; /* flags on received message */
};
msg_name and msg_namelen are not used with stream
protocols.
For stream sockets ,
set msg_name to NULL and msg_namelen to zero.
msg_iov and msg_iovlen describe a set of buffers that
are sent or received.
msg_flags – should set to zero.
Struct cmsghdr
{
Unsigned int cmsg_len; /length of control msg
Int cmsg_level; //SOL_SOCKET
Int cmsg_type; //SCM_RIGHTS
Int cmsg_data[0];//file descriptor gots here
}
NETWORKING MACHINES WITH TCP/IP
#include <netinet/in.h>
unsigned int htonl(unsigned int hostlong); unsigned
short htons(unsigned short hostshort);
Above 2 functions, convert longs and shorts,
respectively, from host order to network order.
unsigned int ntohl(unsigned int netlong); unsigned short
ntohs(unsigned short netshort);
Above 2 functions ,convert longs and shorts from network
order to the host byte ordering.
IPV4 ADDRESSING
Struct servent{
Char *s_name;
Char **s_aliases;
Int s_port;
Char *s_proto;
}
htons() function converts the unsigned short
integer hostshort from host byte order to network byte
order.
void *memset(void *s, int c, size_t n);