diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
commit | 6c027b4de25a529908be895e7ff19236f4002a57 (patch) | |
tree | f70d3a400bbb9ba8a83e9d4ffcaa4b6e367fc8bb /socket_bind.c | |
download | crypto-6c027b4de25a529908be895e7ff19236f4002a57.zip crypto-6c027b4de25a529908be895e7ff19236f4002a57.tar.gz |
initial commit, resurrect one of my realy old projects
Diffstat (limited to 'socket_bind.c')
-rw-r--r-- | socket_bind.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/socket_bind.c b/socket_bind.c new file mode 100644 index 0000000..5a6a0a0 --- /dev/null +++ b/socket_bind.c @@ -0,0 +1,33 @@ +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#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); + } +} |