ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_bind.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/param.h>
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include "byte.h"
6 #include "socket.h"
7 
8 int socket_bind4(int s,const char ip[4],uint16 port)
9 {
10  struct sockaddr_in sa;
11 
12  byte_zero(&sa,sizeof sa);
13  sa.sin_family = AF_INET;
14  uint16_pack_big((char *) &sa.sin_port,port);
15  byte_copy((char *) &sa.sin_addr,4,ip);
16 
17  return bind(s,(struct sockaddr *) &sa,sizeof sa);
18 }
19 
20 int socket_bind4_reuse(int s,char ip[4],uint16 port)
21 {
22  int opt = 1;
23  setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt);
24  return socket_bind4(s,ip,port);
25 }
26 
27 void socket_tryreservein(int s,int size)
28 {
29  while (size >= 1024) {
30  if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size) == 0) return;
31  size -= (size >> 5);
32  }
33 }
int socket_bind4_reuse(int s, char ip[4], uint16 port)
Definition: socket_bind.c:20
void byte_copy(void *, unsigned int, const void *)
void socket_tryreservein(int s, int size)
Definition: socket_bind.c:27
void uint16_pack_big(char *, uint16)
void byte_zero(void *, unsigned int)
int socket_bind4(int s, const char ip[4], uint16 port)
Definition: socket_bind.c:8
unsigned short uint16
Definition: uint16.h:4