-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSysCheckInCmd.c
142 lines (74 loc) · 1.7 KB
/
SysCheckInCmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* -- $Id: SysCheckInCmd.cpp,v 1.12.2.1.4.3 2004/07/22 11:14:41 yuzhe Exp $ -- */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "SysCheckInCmd.h"
#include "SysConfExt.h"
#include "NetLog.h"
#include "Debuger.h"
#include "CtrlLinkTbl.h"
#include "Protocol.h"
int
SysCheckInCmd (int sock_fd)
{
//-- 登记客户端连接 --//
int i;
int pos = -1;
unsigned long ipaddr;
struct sockaddr_in sockaddr;
unsigned int salen = sizeof (sockaddr);
PCTRL_LINK_DESC pcld;
TRACE (12, (" #### Enter SYS_CHECKIN_REQ #### \n"));
getpeername (sock_fd, (struct sockaddr *) &sockaddr, &salen);
ipaddr = sockaddr.sin_addr.s_addr;
pcld = CtrlLinkTbl;
for (i = 0; i < MAX_CONN_NUM; i++, pcld++)
{
if (pcld->socket_fd != 0)
{
if (pcld->ipaddr == ipaddr)
{
// repeated link
TRACE (6,
("Repeated connection from same ip address\n"));
goto FAIL;
}
}
else if (-1 == pos)
{
pos = i;
}
}
if (-1 == pos)
{
// Link Table is full
TRACE (6, ("Link Ctrl Table is full!\n"));
goto FAIL;
}
else
{
// 找到空表项
pcld = CtrlLinkTbl;
pcld += pos;
pthread_mutex_lock (&pcld->mutex);
// strncpy(pcld->username, username, MAX_USRNAME_LEN);
pcld->socket_fd = sock_fd;
pcld->ipaddr = ipaddr;
/* pthread_self
* PURPOSE
* return identifier of current thread
*/
pcld->ctrl_tid = pthread_self ();
pthread_mutex_unlock (&pcld->mutex);
}
return 0;
FAIL:TRACE (12, (" #### FINISHED SYS_CHECKIN_REQ #### \n"));
return -1;
}