void int_event_module(void)
{
	notify_fd = udp_create();

	if (notify_fd == -1)
		exit(-1);
}
Beispiel #2
0
/* open the helper socket used by helper processes to receive requests
 *	must be called with the counter mutex */
static u_char
open_helper_soc(DCC_CLNT_CTXT *ctxt, void *logp)
{
	socklen_t soc_len;
	static int rcvbuf = 32*1024;
	static u_char rcvbuf_set;
	char sustr[DCC_SU2STR_SIZE];
	DCC_EMSG emsg;

	rcvbuf_set = 0;

	/* We want to create a new socket with the same choice of
	 * IPv4 or IPv6 as the DCC client context's socket.  To do that,
	 * try to ensure that the context's socket is healthy. */
	dcc_ctxts_lock();
	if (!dcc_clnt_rdy(emsg, ctxt,
			  DCC_CLNT_FG_BAD_SRVR_OK
			  | DCC_CLNT_FG_NO_MEASURE_RTTS
			  | DCC_CLNT_FG_NO_FAIL)
	    || !dcc_info_unlock(emsg))
		thr_trace_msg(logp, "DNSBL helper: %s", emsg);
	dcc_ctxts_unlock();
	dcc_mk_loop_su(&helper.su, ctxt->soc[0].loc.sa.sa_family, 0);

	dcc_clean_stdio();
	if (!udp_create(emsg, &helper.soc, &helper.su, 0)) {
		thr_error_msg(logp, "DNSBL helper bind(%s): %s",
			      dcc_su2str(sustr, sizeof(sustr), &helper.su),
			      emsg);
		terminate_helpers();
		return 0;
	}
	soc_len = sizeof(helper.su);
	if (0 > getsockname(helper.soc, &helper.su.sa, &soc_len)) {
		thr_error_msg(logp, "DNSBL helper getsockname(%d, %s): %s",
			      helper.soc, dcc_su2str(sustr, sizeof(sustr),
						     &helper.su),
			      ERROR_STR());
		terminate_helpers();
		return 0;
	}
	for (;;) {
		if (!setsockopt(helper.soc, SOL_SOCKET, SO_RCVBUF,
				&rcvbuf, sizeof(rcvbuf)))
			break;
		if (rcvbuf_set || rcvbuf <= 4096) {
			thr_error_msg(logp,
				      "DNSBL setsockopt(%s,SO_RCVBUF=%d): %s",
				      dcc_su2str(sustr, sizeof(sustr),
						 &helper.su),
				      rcvbuf, ERROR_STR());
			break;
		}
		rcvbuf -= 4096;
	}
	rcvbuf_set = 1;
	return 1;
}
Beispiel #3
0
int ScanStb(JNIEnv* env, jobject thiz)
{
	int recvsocket;
	char buf[80];
	in_addr n;
	int i;

	pplay->stbnum = 0;
	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "ScanStbfunc started\n");
	recvsocket = udp_create(5211);

	if(recvsocket < 0)
	{
		return -1;
	}

	if(sendbrocast(recvsocket, 5210) < 0)
	{
		close(recvsocket);
		return -1;
	}
	
	while(1)
	{
		if(udp_recv(recvsocket, NORMAL_DELAY, buf) < 0)
			break;
		for(i = 0; i < pplay->stbnum; i++)
		{
//			__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "stb %d ip is %s %s %d\n", i, buf, pplay->stbip[i], strcmp(buf, pplay->stbip[i]));
			if(strcmp(buf, pplay->stbip[i]) == 0)
				break;
		}
		if(i == pplay->stbnum)
		{
			strcpy(pplay->stbip[pplay->stbnum], buf);
			pplay->stbnum++;
		}
	}
	close(recvsocket);
	for(i = 0; i < pplay->stbnum; i++)
		__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "stb %d ip is %s\n", i, pplay->stbip[i]);
	return pplay->stbnum;
}
Beispiel #4
0
int dhcp_transport_init(dhcp_transport_t *dt, service_id_t link_id,
    dhcp_recv_cb_t recv_cb, void *arg)
{
	udp_t *udp = NULL;
	udp_assoc_t *assoc = NULL;
	inet_ep2_t epp;
	int rc;

	log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcp_transport_init()");

	inet_ep2_init(&epp);
	epp.local.addr.version = ip_v4;
	epp.local.port = dhcp_client_port;
	epp.local_link = link_id;

	rc = udp_create(&udp);
	if (rc != EOK) {
		rc = EIO;
		goto error;
	}

	rc = udp_assoc_create(udp, &epp, &dhcp_transport_cb, dt, &assoc);
	if (rc != EOK) {
		rc = EIO;
		goto error;
	}

	dt->udp = udp;
	dt->assoc = assoc;
	dt->recv_cb = recv_cb;
	dt->cb_arg = arg;

	return EOK;
error:
	udp_assoc_destroy(assoc);
	udp_destroy(udp);
	return rc;
}
Beispiel #5
0
int main (int argc, char * argv [])
  {
    int rc;
    int linkno;
    rc = udp_create ("4500::4426", & linkno);
    if (rc < 0)
      {
        printf ("udp_create failed\n");
        exit (1);
      }

    while (1)
      {
#define psz 17000
        uint16_t pkt [psz];
        rc = udp_receive (linkno, pkt, psz);
        if (rc < 0)
          {
            printf ("udp_receive failed\n");
            exit (1);
          }
        else if (rc == 0)
          {
            printf ("udp_receive 0\n");
            sleep (1);
          }
        else
          {
            for (int i = 0; i < rc; i ++)
              {
                printf ("  %06o  %04x  ", pkt [i], pkt [i]);
                for (int b = 0; b < 16; b ++)
                  printf ("%c", pkt [i] & (1 << b) ? '1' : '0');
                printf ("\n");
              }
          }
      }
  }
Beispiel #6
0
static int global_create6(lua_State *L) {
    return udp_create(L, AF_INET6);
}
Beispiel #7
0
static int global_create(lua_State *L) {
    return udp_create(L, AF_UNSPEC);
}