ucspi-ssl  0.99e
TLS encryption for IPv6 communication
socket_conn.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 <unistd.h>
6 #include "byte.h"
7 #include "socket.h"
8 
9 int socket_connect4(int s,const char ip[4],uint16 port)
10 {
11  struct sockaddr_in sa;
12 
13  byte_zero(&sa,sizeof sa);
14  sa.sin_family = AF_INET;
15  uint16_pack_big((char *) &sa.sin_port,port);
16  byte_copy((char *) &sa.sin_addr,4,ip);
17 
18  return connect(s,(struct sockaddr *) &sa,sizeof sa);
19 }
20 
21 int socket_connected(int s)
22 {
23  struct sockaddr_in sa;
24  socklen_t dummy = sizeof sa;
25  char ch;
26 
27  if (getpeername(s,(struct sockaddr *) &sa,&dummy) == -1) {
28  read(s,&ch,1); /* sets errno */
29  return 0;
30  }
31  return 1;
32 }
void byte_copy(void *, unsigned int, const void *)
void uint16_pack_big(char *, uint16)
int socket_connected(int s)
Definition: socket_conn.c:21
int socket_connect4(int s, const char ip[4], uint16 port)
Definition: socket_conn.c:9
void byte_zero(void *, unsigned int)
unsigned short uint16
Definition: uint16.h:4