Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pBlueG committed Aug 1, 2014
1 parent 5b2997a commit 64df9e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions socket.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define INVALID_SOCKET (-1)
#define INVALID_CLIENT_ID (-1)
#define NO_IP_RETURN "0.0.0.0"
#define INADDR_ANY NO_IP_RETURN

// SSL related
#define METHOD_CLIENT 0 //v23
Expand Down Expand Up @@ -51,11 +52,11 @@ native get_remote_client_ip(Socket:id, remote_clientid, ip[]); // tcp only
native ssl_init(); // initialize the ssl library
native ssl_create_context(Socket:id, method);
native ssl_connect(Socket:id); // tcp (client only)
native ssl_load_cert_into_context(Socket:id, const certificate[], const private_key[]);
native ssl_load_cert_into_context(Socket:id, const certificate[], const private_key[]); // certificate & private_key might be the same .pem file
native ssl_shutdown(Socket:id) = socket_destroy;
native ssl_get_peer_certificate(Socket:id, method, subject[], issuer[], remote_clientid = 0xFFFF);
native ssl_set_accept_timeout(Socket:id, interval);
native ssl_set_mode(Socket:id, mode);
native ssl_set_accept_timeout(Socket:id, interval); // interval in miliseconds
native ssl_set_mode(Socket:id, mode); // see above SSL_modes (enum)


// client & server (udp)
Expand Down
3 changes: 0 additions & 3 deletions socket/CNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ cell AMX_NATIVE_CALL n_ssl_init(AMX* amx, cell* params)
return 1;
}

//g_pSocket->m_pSocketInfo[sockID].ssl_clients[slot]
// native ssl_get_peer_certificate(Socket:id, method, subject[], issuer[], remote_clientid = 0xFFFF);

cell AMX_NATIVE_CALL n_ssl_get_peer_certificate(AMX* amx, cell* params)
{
char *szIssuer, *szSubject;
Expand Down
15 changes: 9 additions & 6 deletions socket/CSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int CSocket::connect_socket(int socketid, char* address, int port)
sockaddr_in bind_addr;
bind_addr.sin_addr.s_addr = inet_addr(m_pSocketInfo[socketid].bind_ip);
bind_addr.sin_family = AF_INET;
if(bind(m_pSocket[socketid], (struct sockaddr *)&bind_addr, sizeof(bind_addr)) == -1) {
if(bind(m_pSocket[socketid], (struct sockaddr *)&bind_addr, sizeof(bind_addr)) == SOCKET_ERROR) {
logprintf("socket_connect(): Socket ID %d has failed to bind. (IP %s, Port %s).", socketid, m_pSocketInfo[socketid].bind_ip);
return 0;
}
Expand All @@ -123,20 +123,22 @@ int CSocket::listen_socket(int socketid, int port)
return 0;
}
struct sockaddr_in addr;
memset((char *)&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
memset(&(addr.sin_zero), 0, 8);
if(strcmp(m_pSocketInfo[socketid].bind_ip, "0.0.0.0") != 0)
addr.sin_addr.s_addr = htonl(INADDR_ANY);
else
addr.sin_addr.s_addr = inet_addr(m_pSocketInfo[socketid].bind_ip);
if(bind(m_pSocket[socketid], (struct sockaddr *)&addr, sizeof(addr)) == -1) {
if(bind(m_pSocket[socketid], (struct sockaddr *)&addr, sizeof(addr)) == SOCKET_ERROR) {
logprintf("socket_listen(): Socket has failed to bind. (IP %s, Port %d)", m_pSocketInfo[socketid].bind_ip, port);
logprintf(" The port might be already in use.");
return 0;
}
if(m_pSocketInfo[socketid].tcp) {
if(listen(m_pSocket[socketid], 10) == -1) {
if(m_pSocketInfo[socketid].tcp) {
if(listen(m_pSocket[socketid], 10) == SOCKET_ERROR) {
logprintf("socket_listen(): Socket has failed to listen on port %d.", port);
logprintf(" The port might be already in use.");
return 0;
}
}
Expand Down Expand Up @@ -238,8 +240,9 @@ int CSocket::sendto_socket(int socketid, char* ip, int port, char* data, int len
}
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = port;
serv_addr.sin_port = htons(port);
serv_addr.sin_addr.s_addr = inet_addr(ip);
logprintf("Sendto %s | %s | %d | %d", ip, data, port, len);
return sendto(m_pSocket[socketid], data, len, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
}
//return sendto(m_pSocket[socketid], data, len, 0, (struct sockaddr *)&addr, sizeof(addr));
Expand Down
3 changes: 3 additions & 0 deletions socket/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@

typedef void (*logprintf_t)(char* format, ...);

#ifndef SOCKET_ERROR
#define SOCKET_ERROR -1
#endif

struct remoteConnect {
int socketid;
Expand Down

0 comments on commit 64df9e2

Please sign in to comment.