Exemple #1
0
map_session_data_t* mapsession_createsession(uint32 ip, uint16 port)
{
    map_session_data_t* map_session_data = new map_session_data_t;
    memset(map_session_data, 0, sizeof(map_session_data_t));

    CREATE(map_session_data->server_packet_data, int8, map_config.buffer_size + 20);

    map_session_data->last_update = time(nullptr);
    map_session_data->client_addr = ip;
    map_session_data->client_port = port;

    uint64 port64 = port;
    uint64 ipp = ip;
    ipp |= port64 << 32;
    map_session_list[ipp] = map_session_data;

	const int8* fmtQuery = "SELECT charid FROM accounts_sessions WHERE inet_ntoa(client_addr) = '%s' LIMIT 1;";

	int32 ret = Sql_Query(SqlHandle, fmtQuery, ip2str(map_session_data->client_addr, nullptr));

	if (ret == SQL_ERROR ||
		Sql_NumRows(SqlHandle) == 0)
	{
		ShowError(CL_RED"recv_parse: Invalid login attempt from %s\n" CL_RESET, ip2str(map_session_data->client_addr, nullptr));
		return nullptr;
	}
    return map_session_data;
}
Exemple #2
0
void
usrv_task(intptr_t exinf)
{
	static uint8_t buffer[BUF_SIZE];

	T_IPV4EP	dst;
	T_IN4_ADDR	addr;
	ER_UINT		len;
	ID		tskid;

	get_tid(&tskid);
	addr = IPV4_ADDR_LOCAL;
	syslog(LOG_NOTICE, "[UDP ECHO SRV:%d,%d] started, IP Address: %s.", 
	                   tskid, (ID)exinf, ip2str(NULL, &addr));
	while (true) {
		if ((len = udp_rcv_dat((ID)exinf, &dst, buffer, sizeof(buffer), 20 * 1000)) >= 0) {
			buffer[len] = '\0';
			syslog(LOG_NOTICE, "[UDP ECHO SRV] recv, addr: %s:%d, len: %d, msg: '%s'",
			                   ip2str(NULL, &dst.ipaddr), dst.portno, len, buffer);
			if ((int)len > 0) {
				if ((len = udp_snd_dat((ID)exinf, &dst, buffer, len, TMO_FEVR)) < 0)
					syslog(LOG_NOTICE, "[UDP ECHO SRV] send, error: %s", itron_strerror(len));
				}
			}
		else
			syslog(LOG_NOTICE, "[UDP ECHO SRV] recv, error: %s", itron_strerror(len));
		}
	}
Exemple #3
0
static int setup_named_sock(char *listen_addr, int listen_port, struct socketlist *socklist)
{
	struct sockaddr_in sin;
	int sockfd;
	long flags;

	memset(&sin, 0, sizeof sin);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(listen_port);

	if (listen_addr) {
		/* Well, host better be an IP address here. */
		if (inet_pton(AF_INET, listen_addr, &sin.sin_addr.s_addr) <= 0)
			return 0;
	} else {
		sin.sin_addr.s_addr = htonl(INADDR_ANY);
	}

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
		return 0;

	if (set_reuse_addr(sockfd)) {
		logerror("Could not set SO_REUSEADDR: %s", strerror(errno));
		close(sockfd);
		return 0;
	}

	set_keep_alive(sockfd);

	if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
		logerror("Could not bind to %s: %s",
			 ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
			 strerror(errno));
		close(sockfd);
		return 0;
	}

	if (listen(sockfd, 5) < 0) {
		logerror("Could not listen to %s: %s",
			 ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
			 strerror(errno));
		close(sockfd);
		return 0;
	}

	flags = fcntl(sockfd, F_GETFD, 0);
	if (flags >= 0)
		fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);

	ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);
	socklist->list[socklist->nr++] = sockfd;
	return 1;
}
Exemple #4
0
//======================================================================================
bool TcpSocket::Connect(uint32_t uiIP, uint16_t iPort, bool async)
{
	Log.i(SOCK_TAG, "TcpSocket::Connect uiIp:%u. iPort:%u, async:%s", uiIP, iPort, async ? "async" : "sync");
	WSADATA	wd;
	int result = WSAStartup(MAKEWORD(1, 1), &wd);
	if(result != 0){
		Log.e(SOCK_TAG, "WSAStartup failed, error code %u", result);
		return false;
	} 
	m_iSocket = socket(AF_INET, SOCK_STREAM, 0);
	if (m_iSocket == -1){
		int errorCode = WSAGetLastError();
		Log.e(SOCK_TAG, "TcpSocket::Connect socket fail, error code %u.", errorCode);
		return false;
	}

	struct sockaddr_in address;
	memset(&address, 0, sizeof(address));
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = uiIP;
	address.sin_port = htons(iPort);

	m_ip = uiIP;
	m_iPort = htons(iPort);

	if (async)
	{
		Log.i(SOCK_TAG, "Set non block.");
		m_bConnected = false;
		SetNBlock();
		m_iLastRecvTime = SelectorEPoll::getInstance().m_iHaoMiao;
		m_pSelector->SetEvent(this, 0, SEL_RW);
	}

	if (connect(m_iSocket, (struct sockaddr*) &address, sizeof(address)) == -1) {
		int errorCode = WSAGetLastError();
		if (errorCode == WSAEWOULDBLOCK){
			Log.d(SOCK_TAG, "TcpSocket::Connect in progress. ip=%s", ip2str(uiIP));
			return true;
		}
		Log.w(SOCK_TAG, " TcpSocket::Connect %s:%u fail. error code: %u", ip2str(uiIP), iPort, errorCode);
		CloseSocket();
		return false;
	}

	m_iLastRecvTime = SelectorEPoll::getInstance().m_iHaoMiao;
	m_bConnected = true;
	SetNBlock();
	m_pSelector->SetEvent(this, 0, SEL_RW);
	return true;
}
Exemple #5
0
/* Ping using the raw ip */
static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p,
                      struct ip_addr *addr)
{
        struct icmp_echo_hdr *iecho;
        struct ip_hdr *ip = p->payload;
        struct ping_info_t* ping_info = (struct ping_info_t*) arg;
        uint32_t us;

#if ( (LWIP_VERSION) != ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
        struct ip_addr ip_adr;

        /* to get unpacked version without losing alignment */
        memcpy(&ip_adr, &(ip->src), sizeof(ip_adr));
#endif
        if (pbuf_header( p, -PBUF_IP_HLEN)==0) {
                iecho = p->payload;

                if ((iecho->id == PING_ID) &&
                    (iecho->seqno == htons(ping_info->seq_num))) {
                        ping_info->last_rx_tm = timer_get_ms();
                        ping_info->num_rx++;
                        us = 1000 *
                                (ping_info->last_rx_tm - ping_info->last_tx_tm);

                        if (!ping_info->quiet)
#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
                                printk("%d bytes from %s: icmp_seq=%d ttl=%d " \
                                       "time=%d.%03d ms\n",
                                       p->tot_len, ip2str(ip->src),
                                       ntohs(iecho->seqno),
                                       IPH_TTL(ip),
                                       us / 1000, us % 1000);
#else
                                printk("%d bytes from %s: icmp_seq=%d ttl=%d " \
                                       "time=%d.%03d ms\n",
                                       p->tot_len, ip2str(ip_adr),
                                       ntohs(iecho->seqno),
                                       IPH_TTL(ip),
                                       us / 1000, us % 1000);

#endif

                        /* do some ping result processing */
                        ping_info->flags |= PING_REPLY;
                }
        }

        pbuf_free(p);
        return 1; /* eat the event */
}
Exemple #6
0
//======================================================================================
int TcpSocket::SendBin(uint32_t ip, uint16_t port, const char* data, uint32_t len) {
	if (m_output.max_blocks < m_output.block()) {
		Log.e(SOCK_TAG, "tcp socket send buffer error max block:%u current:%u, %s",
			m_output.max_blocks, m_output.block(), ip2str(m_ip));
		return 0;
	}

	if (m_bEnanbe) {
		if (m_bConnected) {
			//m_output.write(*this, (char*) data, len);
			m_output.pushData(data, len);
			int res = m_output.flush(m_iSocket);
			if(res < 0){
				Log.w(SOCK_TAG, "TcpSocket::SendBin close the socket reset by peer socketL:%u addr:%s",m_iSocket, ip2str(m_ip));
				m_pHandler->onClose(this);
				m_bEnanbe = false;
				return 0;
			}
			if (!m_output.empty()){
				m_pSelector->SetEvent(this, 0, SEL_WRITE);
			}
		}
	} else {
		//log(Info, "socket not enable: %s", sox::addr_ntoa(peerIp).data());
		Log.i(SOCK_TAG, "socket not enable");
	}
	return 0;
}
Exemple #7
0
/* Ping using the raw ip */
static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p,
                      struct ip_addr *addr)
{
        struct icmp_echo_hdr *iecho;
        struct ip_hdr *ip = p->payload;
        struct ping_info_t* ping_info = (struct ping_info_t*) arg;
        uint32_t us;

        if (pbuf_header( p, -PBUF_IP_HLEN)==0) {
                iecho = p->payload;

                if ((iecho->id == PING_ID) &&
                    (iecho->seqno == htons(ping_info->seq_num))) {
                        ping_info->last_rx_tm = timer_get_ms();
                        ping_info->num_rx++;
                        us = 1000 *
                                (ping_info->last_rx_tm - ping_info->last_tx_tm);

                        if (!ping_info->quiet)
                                printk("%d bytes from %s: icmp_seq=%d ttl=%d " \
                                       "time=%d.%03d ms\n",
                                       p->tot_len, ip2str(ip->src),
                                       iecho->seqno,
                                       IPH_TTL(ip),
                                       us / 1000, us % 1000);
                        
                        /* do some ping result processing */
                        ping_info->flags |= PING_REPLY;
                }
        }

        pbuf_free(p);
        return 1; /* eat the event */
}
Exemple #8
0
void device_info(char *dev)
{
    char errbuf[PCAP_ERRBUF_SIZE];
    int ret = 0;

    bpf_u_int32 netp;   /* ip          */
    bpf_u_int32 maskp;  /* subnet mask */

    ret = pcap_lookupnet(dev, &netp, &maskp, errbuf);

    if(ret == -1)
        die(errbuf);

    fprintf(stderr, "Device: %s\nIP: %s\n", dev, ip2str(netp));
    fprintf(stderr, "Netmask: %s\n", ip2str(maskp));
}
Exemple #9
0
static int
export_srv_spec(ilb_server_data_t *srv, char *buf, const int bufsize)
{
	int	len = 0, bufsz = (int)bufsize;

	ip2str(&srv->sd_addr, buf, bufsz, 0);

	len += strlen(buf);
	bufsz -= len;

	if (srv->sd_minport != 0) {
		in_port_t	h_min, h_max;
		int		inc;

		h_min = ntohs(srv->sd_minport);
		h_max = ntohs(srv->sd_maxport);

		/* to do: if service name was given, print that, not number */
		if (h_max <= h_min)
			inc = snprintf(buf+len, bufsz, ":%d", h_min);
		else
			inc = snprintf(buf+len, bufsz, ":%d-%d", h_min, h_max);

		if (inc > bufsz) /* too little space */
			return (-1);
		len += inc;
	}

	return (len);
}
Exemple #10
0
//======================================================================================
TcpSocket* TcpSocket::Accept() {
	struct sockaddr_in sa;
	socklen_t len = sizeof(sa);
	Log.i(SOCK_TAG, "TcpSocket::Accept m_iSocket=%u", m_iSocket);
	int ret = accept(m_iSocket, (struct sockaddr*) &sa, &len);
	if (-1 == ret){
		Log.e(SOCK_TAG, "TcpSocket::Accept -1!");
		return NULL;
	}
	if (0 == ret) {
		Log.e(SOCK_TAG, "TcpSocket::Accept 0!");
		return NULL;
	}

	TcpSocket *pNew = new TcpSocket(m_pSelector);
	pNew->m_iSocket = ret;
	//pNew->m_ip = ntohl(sa.sin_addr.s_addr);
	//pNew->m_iPort = ntohs(sa.sin_port);
	pNew->m_ip = sa.sin_addr.s_addr;
	pNew->m_iPort = sa.sin_port;
	pNew->m_bConnected = true;
	pNew->m_iLastRecvTime = SelectorEPoll::getInstance().m_iHaoMiao;
	pNew->setTimeout(m_iTimeout);
	pNew->SetNBlock();
	Log.i(SOCK_TAG, "TcpSocket accept %s:%u", ip2str(pNew->m_ip), pNew->m_iPort);
	return pNew;
}
Exemple #11
0
static void display(leeloo::ip_interval const& it)
{
	const uint32_t width = it.width();
	const char* ip_a = ip2str(it.lower());
	if (__builtin_popcount(width) == 1) {
		// CIDR prefix
		const int prefix = 32-__builtin_ctz(width);
		std::cout << ip_a << "/" << prefix << std::endl;
	}
	else {
		// AG: as a static buffer is used for inet_ntoa, we need to make two
		// std::cout statements here, or the same IP will be shown twice!
		std::cout << ip_a << "-"; 
		std::cout << ip2str(it.upper()) << std::endl;
	}
}
Exemple #12
0
int32 map_decipher_packet(int8* buff, size_t size, sockaddr_in* from, map_session_data_t* map_session_data)
{
    uint16 tmp, i;

    // counting blocks whose size = 4 byte
    tmp = (size - FFXI_HEADER_SIZE) / 4;
    tmp -= tmp % 2;

#   ifdef WIN32
    uint32 ip = ntohl(from->sin_addr.S_un.S_addr);
#   else
    uint32 ip = ntohl(from->sin_addr.s_addr);
#   endif

    blowfish_t *pbfkey = &map_session_data->blowfish;

    for (i = 0; i < tmp; i += 2)
    {
        blowfish_decipher((uint32*)buff + i + 7, (uint32*)buff + i + 8, pbfkey->P, pbfkey->S[0]);
    }

    if (checksum((uint8*)(buff + FFXI_HEADER_SIZE), size - (FFXI_HEADER_SIZE + 16), buff + size - 16) == 0)
    {
        return 0;
    }

    int8 ip_str[16];
    ShowError("map_encipher_packet: bad packet from <%s>\n", ip2str(ip, ip_str));
    return -1;
}
Exemple #13
0
void do_send_task(int fd, t_task_base *base, t_pfs_sig_head *h)
{
	struct conn *curcon = &acon[fd];
	curcon->send_len = 0;
	char obuf[2048] = {0x0};
	pfs_cs_peer *peer = (pfs_cs_peer *) curcon->user;
	peer->hbtime = time(NULL);
	uint8_t tmp_status = FILE_SYNC_DST_2_SRC;

	if (base->fsize == 0 || base->retry)
	{
		if (get_localfile_stat(base) != LOCALFILE_OK)
		{
			LOG(pfs_data_log, LOG_ERROR, "filename[%s] get_localfile_stat ERROR %m!\n", base->filename);
			tmp_status = FILE_SYNC_DST_2_SRC_E_OPENFILE;
		}
	}

	if (tmp_status == FILE_SYNC_DST_2_SRC)
	{
		t_pfs_tasklist *task = NULL;
		if (pfs_get_task(&task, TASK_Q_HOME))
		{
			LOG(pfs_data_log, LOG_ERROR, "filename[%s] do_newtask ERROR!\n", base->filename);
			tmp_status = FILE_SYNC_DST_2_SRC_E_MALLOC;
		}
		else
		{
			memset(&(task->task), 0, sizeof(task->task)); 
			t_task_sub *sub = &(task->task.sub);
			memset(sub, 0, sizeof(t_task_sub));
			ip2str(sub->peerip, peer->ip);
			sub->processlen = base->fsize;
			sub->starttime = time(NULL);
			sub->oper_type = OPER_GET_RSP;
			sub->need_sync = TASK_SRC_NOSYNC;
			memcpy(&(task->task.base), base, sizeof(t_task_base));

			int lfd = -1;
			if (open_localfile_4_read(base, &lfd) != LOCALFILE_OK)
			{
				LOG(pfs_data_log, LOG_ERROR, "fd[%d] err open [%s] %m close it\n", fd, base->filename);
				tmp_status = FILE_SYNC_DST_2_SRC_E_OPENFILE;
				task->task.base.overstatus = OVER_E_OPEN_SRCFILE;
				pfs_set_task(task, TASK_Q_FIN);
			}
			else
			{
				task->task.base.overstatus = OVER_UNKNOWN;
				pfs_set_task(task, TASK_Q_SEND);
				peer->sendtask = task;
				set_client_fd(fd, lfd, 0, sub->processlen);
				peer->sock_stat = SENDFILEING;
			}
		}
	}
	int n = create_sig_msg(CMD_GET_FILE_RSP, tmp_status, (t_pfs_sig_body *)base, obuf, sizeof(t_task_base));
	set_client_data(fd, obuf, n);
	peer->headlen = n;
}
Exemple #14
0
ER dhcp_offer(DHCP *dhcp)
{
    ER         ercd;
    T_IPV4EP   p_dstaddr;
	T_IN4_ADDR tipaddr;
    static UB  ipaddr[sizeof("000.000.000.000") + 1];

    p_dstaddr.ipaddr = BROADCAST_ADDR;
    p_dstaddr.portno = BROADCAST_PORT;

    ercd = udp_rcv_dat(UDP_CLIENT_CEPID, &p_dstaddr, (VP)&udp_rbuf, sizeof(DHCP_PACKET), TIMEOUT);
                                                                 /* タイムアウトは2秒を指定 */
    syslog(LOG_NOTICE, "[dhcp_offer] ercd = %d", ercd);
    if(ercd > 0){
        if((dhcp_packet->transaction_id == htonl(TRANSACTION_ID)) &&
          (dhcp_packet->options.message_type1[0] == 0x35) &&     /* DHCP Message */
          (dhcp_packet->options.message_type1[1] == 0x01) &&     /* Option Data Length */
          (dhcp_packet->options.message_type2 == DHCP_OFFER)) {  /* DHCP Offer */
            memcpy((VP)dhcp->ipaddr, (const VP)dhcp_packet->user_ip, 4);
			tipaddr = htonl(*((UW *)dhcp->ipaddr));				/* for endian */
            ip2str(ipaddr, (const T_IN4_ADDR *)&tipaddr);
            syslog(LOG_NOTICE, "[dhcp_offer] ip_addr = %s", ipaddr);
        }
    }

    return ercd;
}
Exemple #15
0
/**
 * Entry point from char-server to log-server.
 * Function that checks incoming command, then splits it to the correct handler.
 * @param fd: file descriptor to parse, (link to char-serv)
 * @return 0=invalid server,marked for disconnection,unknow packet; 1=success
 */
int logchrif_parse(int fd){
	int cid; //char-serv id
	uint32 ipl;
	char ip[16];

	ARR_FIND( 0, ARRAYLENGTH(ch_server), cid, ch_server[cid].fd == fd );
	if( cid == ARRAYLENGTH(ch_server) ){// not a char server
		ShowDebug("logchrif_parse: Disconnecting invalid session #%d (is not a char-server)\n", fd);
		set_eof(fd);
		do_close(fd);
		return 0;
	}

	if( session[fd]->flag.eof ){
		do_close(fd);
		ch_server[cid].fd = -1;
		logchrif_on_disconnect(cid);
		return 0;
	}

	ipl = ch_server[cid].ip;
	ip2str(ipl, ip);

	while( RFIFOREST(fd) >= 2 ){
		int next = 1; // 0: avoid processing followup packets (prev was probably incomplete) packet, 1: Continue parsing
		uint16 command = RFIFOW(fd,0);
		switch( command ){
			case 0x2712: next = logchrif_parse_reqauth(fd, cid, ip); break;
			case 0x2714: next = logchrif_parse_ackusercount(fd, cid); break;
			case 0x2716: next = logchrif_parse_reqaccdata(fd, cid, ip); break;
			case 0x2719: next = logchrif_parse_keepalive(fd); break;
			case 0x2720: next = logchrif_parse_accinfo(fd); break; //@accinfo from inter-server
			case 0x2722: next = logchrif_parse_reqchangemail(fd,cid,ip); break;
			case 0x2724: next = logchrif_parse_requpdaccstate(fd,cid,ip); break;
			case 0x2725: next = logchrif_parse_reqbanacc(fd,cid,ip); break;
			case 0x2727: next = logchrif_parse_reqchgsex(fd,cid,ip); break;
			case 0x2728: next = logchrif_parse_upd_global_accreg(fd,cid,ip); break;
			case 0x272a: next = logchrif_parse_requnbanacc(fd,cid,ip); break;
			case 0x272b: next = logchrif_parse_setacconline(fd,cid); break;
			case 0x272c: next = logchrif_parse_setaccoffline(fd); break;
			case 0x272d: next = logchrif_parse_updonlinedb(fd,cid); break;
			case 0x272e: next = logchrif_parse_req_global_accreg(fd); break;
			case 0x2736: next = logchrif_parse_updcharip(fd,cid); break;
			case 0x2737: next = logchrif_parse_setalloffline(fd,cid); break;
#if PACKETVER_SUPPORTS_PINCODE
			case 0x2738: next = logchrif_parse_updpincode(fd); break;
			case 0x2739: next = logchrif_parse_pincode_authfail(fd); break;
#endif
			case 0x2742: next = logchrif_parse_reqvipdata(fd); break; //Vip sys
			default:
				ShowError("logchrif_parse: Unknown packet 0x%x from a char-server! Disconnecting!\n", command);
				set_eof(fd);
				return 0;
		} // switch
		if (next == 0)
			return 0;
	} // while
	return 1; //or 0
}
Exemple #16
0
static boolean_t
of_ip(ofmt_arg_t *of_arg, char *buf, uint_t bufsize)
{
	sg_srv_o_arg_t	*l = (sg_srv_o_arg_t *)of_arg->ofmt_cbarg;

	ip2str(&l->sd->sd_addr, buf, bufsize, V6_ADDRONLY);
	return (B_TRUE);
}
Exemple #17
0
DNS_STATUS WINAPI hook_DnsQuery_UTF8(PCSTR lpstrName, WORD wType, DWORD Options, PVOID pExtra, PDNS_RECORD *ppQueryResultsSet, PVOID *pReserved)
{
	DebugMsg("DnsQuery_UTF8: %s", lpstrName);
	Options |= DNS_QUERY_USE_TCP_ONLY;
	DNS_STATUS ret = realdnsqueryutf8(lpstrName, wType, Options, pExtra, ppQueryResultsSet, pReserved);
	DebugMsg("Result: from %ls to %s", (*ppQueryResultsSet)->pName, ip2str((*ppQueryResultsSet)->Data.A.IpAddress));
	return ret;
}
Exemple #18
0
static ilbadm_status_t
i_mod_sg(ilb_handle_t h, ilbadm_sgroup_t *sgp, ilbadm_cmd_t cmd,
    int flags)
{
	ilbadm_servnode_t	*sn;
	ilb_server_data_t	*srv;
	ilb_status_t		rclib = ILB_STATUS_OK;
	ilbadm_status_t		rc = ILBADM_OK;

	if (h == ILB_INVALID_HANDLE && cmd != cmd_enable_server &&
	    cmd != cmd_disable_server)
		return (ILBADM_LIBERR);

	sn = list_head(&sgp->sg_serv_list);
	while (sn != NULL) {
		srv = &sn->s_spec;

		srv->sd_flags |= flags;
		if (cmd == cmd_create_sg || cmd == cmd_add_srv) {
			rclib = ilb_add_server_to_group(h, sgp->sg_name,
			    srv);
			if (rclib != ILB_STATUS_OK) {
				char	buf[INET6_ADDRSTRLEN + 1];

				rc = ILBADM_LIBERR;
				ip2str(&srv->sd_addr, buf, sizeof (buf),
				    V6_ADDRONLY);
				ilbadm_err(gettext("cannot add %s to %s: %s"),
				    buf, sgp->sg_name, ilb_errstr(rclib));
				/* if we created the SG, we bail out */
				if (cmd == cmd_create_sg)
					return (rc);
			}
		} else {
			assert(cmd == cmd_rem_srv);
			rclib = ilb_rem_server_from_group(h, sgp->sg_name,
			    srv);
			/* if we fail, we tell user and continue */
			if (rclib != ILB_STATUS_OK) {
				rc = ILBADM_LIBERR;
				ilbadm_err(
				    gettext("cannot remove %s from %s: %s"),
				    srv->sd_srvID, sgp->sg_name,
				    ilb_errstr(rclib));
			}
		}

		/*
		 * list_next returns NULL instead of cycling back to head
		 * so we don't have to check for list_head explicitly.
		 */
		sn = list_next(&sgp->sg_serv_list, sn);
	};

	return (rc);
}
Exemple #19
0
//======================================================================================
void TcpSocket::CloseSocket() {
	if (m_iSocket == -1)
		return;

	Log.d(SOCK_TAG, "TcpSocket::CloseSocket iSocket: %u, %s", m_iSocket, ip2str(m_ip));

	closesocket(m_iSocket);
	m_iSocket = -1;
	m_bConnected = false; // gs 
}
Exemple #20
0
/* ARGSUSED */
static ilb_status_t
ilbadm_list_sg_srv(ilb_handle_t h, ilb_server_data_t *sd, const char *sgname,
    void *arg)
{
	char		ip_str[2*INET6_ADDRSTRLEN + 3] = "";
	char		port_str[INET6_ADDRSTRLEN];
	list_arg_t	*larg = (list_arg_t *)arg;
	ofmt_status_t	oerr;
	int		oflags = 0;
	int		ocols = MAXCOLS;
	int		h_minport, h_maxport;
	static ofmt_handle_t	oh = (ofmt_handle_t)NULL;
	ofmt_field_t	*ofp;

	if (larg->o_str != NULL) {
		if (oh == NULL) {
			if (sd->sd_addr.ia_af == AF_INET)
				ofp = sgfields_v6;
			else
				ofp = sgfields_v4;

			if (larg->flags & ILBADM_LIST_PARSE)
				oflags |= OFMT_PARSABLE;

			oerr = ofmt_open(larg->o_str, ofp, oflags, ocols, &oh);
			if (oerr != OFMT_SUCCESS) {
				char	e[80];

				ilbadm_err(gettext("ofmt_open failed: %s"),
				    ofmt_strerror(oh, oerr, e, sizeof (e)));
				return (ILB_STATUS_GENERIC);
			}
			larg->oh = oh;
		}


		(void) i_list_sg_srv_ofmt((char *)sgname, sd, arg);
		return (ILB_STATUS_OK);
	}

	ip2str(&sd->sd_addr, ip_str, sizeof (ip_str), 0);

	h_minport = ntohs(sd->sd_minport);
	h_maxport = ntohs(sd->sd_maxport);
	if (h_minport == 0)
		*port_str = '\0';
	else if (h_maxport > h_minport)
		(void) sprintf(port_str, ":%d-%d", h_minport, h_maxport);
	else
		(void) sprintf(port_str, ":%d", h_minport);

	(void) printf("%s: id:%s %s%s\n", sgname,
	    sd->sd_srvID?sd->sd_srvID:"(null)", ip_str, port_str);
	return (ILB_STATUS_OK);
}
Exemple #21
0
static void print_stats(struct ping_info_t* ping_info)
{
        printk("\n--- %s ping statistics ---\n",
               ip2str(ping_info->destination));
        printk("%d packets transmitted, %d received, %d%% packet loss, "\
               "time %dms\n\n",
               ping_info->num_tx, ping_info->num_rx,
               100 * (ping_info->num_tx - ping_info->num_rx) /
               ping_info->num_tx,
               timer_get_ms() - ping_info->first_tx_tm);
}
Exemple #22
0
void
tcp_echo_srv_task(intptr_t exinf)
{
    ID		tskid;
    ER_UINT		rlen, slen;
    ER		error = E_OK;
    uint16_t	soff, count, total;

    get_tid(&tskid);
    syslog(LOG_NOTICE, "[TCP ECHO SRV:%d,%d] started.", tskid, (int_t)exinf);
    while (true) {
        if (tcp_acp_cep((int_t)exinf, TCP_ECHO_SRV_REPID, &dst, TMO_FEVR) != E_OK) {
            syslog(LOG_NOTICE, "[TCP ECHO SRV ACP] error: %s", itron_strerror(error));
            continue;
        }

        total = count = 0;
        syslog(LOG_NOTICE, "[TCP ECHO SRV ACP] connected from %s:%d",
               ip2str(NULL, &dst.ipaddr), dst.portno);
        while (true) {
            if ((rlen = tcp_rcv_dat((int_t)exinf, buffer, BUF_SIZE - 1, TMO_FEVR)) <= 0) {
                if (rlen != E_OK)
                    syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] error: %s",
                           itron_strerror(rlen));
                break;
            }

            /*syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] count: %4d, len: %4d, data %02x -> %02x",
                   ++ count, (uint16_t)rlen, *buffer, *(buffer + rlen - 1));*/
            count ++;
            total += (uint16_t)rlen;
            soff = 0;
            while (rlen > 0) {
                if ((slen = tcp_snd_dat((int_t)exinf, &buffer[soff], rlen, TMO_FEVR)) < 0) {
                    syslog(LOG_NOTICE, "[TCP ECHO SRV SND] error: %s",
                           itron_strerror(slen));
                    goto err_fin;
                }
                /*syslog(LOG_NOTICE, "[TCP ECHO SRV SND] len: %d", slen);*/
                rlen -=     slen;
                soff += (uint16_t)slen;
            }
        }
err_fin:

        if ((error = tcp_sht_cep((int_t)exinf)) != E_OK)
            syslog(LOG_NOTICE, "[TCP ECHO SRV SHT] error: %s", itron_strerror(error));

        if ((error = tcp_cls_cep((int_t)exinf, TMO_FEVR)) != E_OK)
            syslog(LOG_NOTICE, "[TCP ECHO SRV CLS] error: %s", itron_strerror(error));

        syslog(LOG_NOTICE, "[TCP ECHO SRV FIN] finished, total cnt: %d, len: %d", count, total);
    }
}
Exemple #23
0
//======================================================================================
TcpSocket::~TcpSocket() {
	Log.i(SOCK_TAG, "TcpSocket::~TcpSocket for socket:%u addr:%s", m_iSocket, ip2str(m_ip));
	m_pSelector->removeSocket((SocketBase*) this);
	CloseSocket();
	m_SockData.uid = -1;
	m_SockData.sid = -1;
	m_SockData.role = -1;
	m_bConnected = false;
	m_bListenSocket = false;
	m_pSelector = NULL;
}
void
show_ip ( void )
{
    struct ip_info info;
    char buf[16];

    wifi_get_ip_info ( STATION_IF, &info );
    // os_printf ( "IP: %08x\n", info.ip );
    // os_printf ( "IP: %s\n", ip2str_i ( buf, info.ip.addr ) );
    os_printf ( "IP: %s\n", ip2str ( buf, (char *) &info.ip.addr ) );
}
void ICACHE_FLASH_ATTR tcp_connect_cb ( void *arg )
{
    struct espconn *conn = (struct espconn *)arg;
    char buf[16];

    os_printf ( "TCP connect\n" );
    os_printf ( "  remote ip: %s\n", ip2str ( buf, conn->proto.tcp->remote_ip ) );
    os_printf ( "  remote port: %d\n", conn->proto.tcp->remote_port );

    espconn_regist_recvcb( conn, tcp_receive_data );
    espconn_regist_sentcb( conn, tcp_send_data );
}
Exemple #26
0
static void
ip_status_cb(struct netif* netif)
{
	INFO_INIT("IP status cb...\n");
        if (netif_is_up(netif)) {
            set_result_cmd(WL_SUCCESS);
            printk("bound to %s\n", ip2str(netif->ip_addr));
            ifStatus = true;
        }else{
        	ifStatus = false;
        	closeConnections();
        	WARN("Interface not up!\n");
        }
}
Exemple #27
0
void add_fd_2_efd(int fd)
{
	epoll_add(epfd, fd, EPOLLIN);
	fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK);

	struct conn *curconn = &acon[fd];
	curconn->fd = fd;
	curconn->send_len = 0;
	memset(curconn->peerip, 0, sizeof(curconn->peerip));
	mybuff_reinit(&(curconn->send_buff));
	mybuff_reinit(&(curconn->recv_buff));
	uint32_t ip = getpeerip(fd);
	ip2str(curconn->peerip, ip);
	LOG(glogfd, LOG_DEBUG, "fd [%d] [%s]set ok %d\n", fd, curconn->peerip, curconn->fd);
}
Exemple #28
0
int 
connection_made(CONN_STATE *csp)
{
	CONN_INFO *cip;

	if (csp == NULL) {
		WLOG_DEBUG("csp is NULL!");
		return (CSF_ERR);
	}
	cip = &(csp->ci);

	ip2str(cip, ip_str, 16);
	WLOG_INFO("Connection made, fd: %d, IP: %s", cip->fd, ip_str);
	connection_counter++;
	csp->data = do_protocol_session_start(cip);
	return (CSF_OK);
}
Exemple #29
0
int 
connection_lost(CONN_STATE *csp)
{
	CONN_INFO *cip;

	if (csp == NULL) {
		WLOG_DEBUG("csp is NULL!");
		return (CSF_OK);
	}
	cip = &(csp->ci);
	ip2str(cip, ip_str, 16);
	WLOG_INFO("Connection closed, fd: %d, IP: %s", cip->fd, ip_str);

	connection_counter--;
	do_protocol_session_end(cip, csp->data);
	
	return (CSF_OK);
}
Exemple #30
0
/**
 * Records an event in the login log.
 * @param ip:
 * @param username:
 * @param rcode:
 * @param message:
 */
void login_log(uint32 ip, const char* username, int rcode, const char* message) {
	char esc_username[NAME_LENGTH*2+1];
	char esc_message[255*2+1];
	int retcode;

	if( !enabled )
		return;

	Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
	Sql_EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255));

	retcode = Sql_Query(sql_handle,
		"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')",
		log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message);

	if( retcode != SQL_SUCCESS )
		Sql_ShowDebug(sql_handle);
}