#include #include #include #include #include "socket.h" #include "uint16.h" int socket_bind4(int s,char ip[4],u16 port) { struct sockaddr_in sa; memset(&sa,0,sizeof sa); sa.sin_family = AF_INET; u16_pack_big((char *) &sa.sin_port,port); memcpy((char *) &sa.sin_addr,ip,4); return bind(s,(struct sockaddr *) &sa,sizeof sa); } int socket_bind4_reuse(int s,char ip[4],u16 port) { int opt = 1; setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt); return socket_bind4(s,ip,port); } void socket_tryreservein(int s,int size) { while (size >= 1024) { if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size) == 0) return; size -= (size >> 5); } }