static void response_client_open_int(response_client_t *uclient, char *conn_str) { char *first, *second, *third; int len, port; memset(uclient->connect_str, 0, sizeof(uclient->connect_str)); strncpy(uclient->connect_str, conn_str, strlen(conn_str)); len = strlen(uclient->connect_str); uclient->connect_str[len] = '\0'; first = conn_str; second = strchr(first, ':'); EXIT_IF_TRUE(second == NULL, "Invalid connection string\n"); *second = '\0'; second++; if( 0 == strcmp(first, "udp") ) { third = strchr(second, ':'); EXIT_IF_TRUE(third == NULL, "Invalid connection string for udp socket\n"); *third = '\0'; third++; port = atoi(third); open_udp_socket(uclient, second, port); } else if( 0 == strcmp(first, "tty") ) { open_tty(uclient, second); } }
/***************************************************************************** * @name * @description * @param * @return */ void send_sip_invite(sip_session_t *session) { int l; char *s; struct sockaddr_in addr; s = gen_call_id(session); session->call->id = (char *) malloc(strlen(s)*sizeof(char)); memcpy(session->call->id,s,strlen(s)); session->call->socket = open_udp_socket(session->localip,0); l = sizeof(addr); if(getsockname(session->call->socket,(struct sockaddr *) &addr,(socklen_t *) &l)) die_with_error("getsockname() failed"); session->call->sport = ntohs(addr.sin_port); s = mk_sip_msg(session,0,INVITE); if((l =sendto(session->socket,s,strlen(s)+1,0,(struct sockaddr *) &(session->addr), sizeof(session->addr)) ) != strlen(s)+1) die_with_error("sendto() failed"); session->prev_state = REGISTERED; session->curr_state = INVITING; }
bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *server, const char *realm, uint32_t *nt_version, union nbt_cldap_netlogon **reply) { int sock; int ret; sock = open_udp_socket(server, LDAP_PORT ); if (sock == -1) { DEBUG(2,("ads_cldap_netlogon: Failed to open udp socket to %s\n", server)); return False; } ret = send_cldap_netlogon(sock, realm, global_myname(), *nt_version); if (ret != 0) { close(sock); return False; } ret = recv_cldap_netlogon(mem_ctx, sock, nt_version, reply); close(sock); if (ret == -1) { return False; } return True; }
int daemon_mode(char *hostname, char* port, int mode) { // ---------------- FOR DAEMON USE, OPEN SOCKETS --------------------------------- // If we choose daemon mode, we will need to open a socket for communication // This needs to be done BEFORE enabling the interrupt handler, as we want // the handler to send its code to the LamPI-daemon process if (mode == SOCK_DGRAM) { if ((sockfd = open_udp_socket()) < 0) { fprintf(stderr,"Error opening UDP socket for host %s. Exiting program\n\n", hostname); exit (1); } else if (verbose) { printf("daemon mode:: Success opening ocket\n"); } } else { // Open a TCP socket if ((sockfd = open_tcp_socket(hostname,port)) < 0) { fprintf(stderr,"Error opening TCP socket for host %s. Exiting program\n\n", hostname); exit (1); } else if (verbose) { printf("daemon mode:: Success connecting TCP to %s:%s\n",hostname,port); } FD_ZERO(&fds); FD_SET(sockfd, &fds); } return(0); }
int main(int argc, char *argv[]) { int rtn; rtn = shared_memory_attach(); T->pid[POLL_IO24_PID].pids = getpid(); mk_daemon(argc,argv); T->pid[POLL_IO24_PID].pids = getpid(); if (rtn == -1) { perror("can not attach to shared memory:\n"); exit(-1); } rtn = io24_message_que_init(); find_io24_addresses(); if (!Daemon) { printf("\nDevice array:\n"); for (rtn = 0; rtn < MAX_DEV;rtn++) { if (Ip_address[rtn][0] != '\0') { printf("%d\t%s\t%c\n",rtn,Ip_address[rtn],Port[rtn][0]); } } printf("\n"); } open_udp_socket(); exit(0); }
void test_udp_client(char *ip, int port, char *cip, int port2) { int sock, addr_from_len, len; int err; struct sockaddr_in addr, addr_from, b_addr; addr_from_len = sizeof(addr_from); sock = open_udp_socket(port); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(10012); err = inet_pton(AF_INET, ip, &addr.sin_addr); // err = inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr); memset((void*) &b_addr, 0, sizeof(b_addr)); b_addr.sin_family = AF_INET; b_addr.sin_port = htons(port2); err = inet_pton(AF_INET, cip, &b_addr.sin_addr); // err = inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr); debug_dump_addr("dst", &addr); char buf[255] = { 0 }; for (;;) { buf[0] = getchar(); err = sendto(sock, buf, 1, 0, (const struct sockaddr *) &addr, sizeof(addr)); err = sendto(sock, buf, 1, 0, (const struct sockaddr *) &b_addr, sizeof(addr)); len = recvfrom(sock, buf, 255, 0, (struct sockaddr*) &addr_from, &addr_from_len); printf("%s <-----", buf); util_dump_addr("from", &addr_from); } }
int send_udp_ipv4_packet( lisp_addr_t *src_addr, lisp_addr_t *dst_addr, uint16_t src_port, uint16_t dst_port, void *packet, int packet_len) { int s = 0; /*socket */ int nbytes = 0; struct sockaddr_in dst; struct sockaddr_in src; if ((s = open_udp_socket(AF_INET)) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "socket: %s", strerror(errno)); return(BAD); } memset((char *) &src, 0, sizeof(struct sockaddr_in)); src.sin_family = AF_INET; src.sin_port = htons(src_port); src.sin_addr.s_addr = src_addr->address.ip.s_addr; static char address[INET6_ADDRSTRLEN]; inet_ntop(AF_INET, &(src.sin_addr), address, INET_ADDRSTRLEN); if (bind(s, (struct sockaddr *)&src, sizeof(struct sockaddr_in)) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "bind: %s", strerror(errno)); close(s); return(BAD); } memset((char *) &dst, 0, sizeof(struct sockaddr_in)); dst.sin_family = AF_INET; dst.sin_addr.s_addr = dst_addr->address.ip.s_addr; dst.sin_port = htons(dst_port); if ((nbytes = sendto(s, (const void *) packet, packet_len, 0, (struct sockaddr *)&dst, sizeof(struct sockaddr_in))) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "sendto: %s", strerror(errno)); close(s); return(BAD); } if (nbytes != packet_len) { LISPD_LOG(LISP_LOG_DEBUG_2, "nbytes (%d) != packet (%d)\n", nbytes, packet_len); close(s); return(BAD); } close(s); return (GOOD); }
int send_udp_ipv6_packet( lisp_addr_t *src_addr, lisp_addr_t *dst_addr, uint16_t src_port, uint16_t dst_port, void *packet, int packet_len) { int s = 0; /*socket */ int nbytes = 0; struct sockaddr_in6 dst; struct sockaddr_in6 src; if ((s = open_udp_socket(AF_INET6)) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "socket: %s", strerror(errno)); return(BAD); } memset((char *) &src, 0, sizeof(struct sockaddr_in6)); src.sin6_family = AF_INET6; src.sin6_port = htons(src_port); memcpy(&src.sin6_addr,&(src_addr->address.ipv6),sizeof(struct in6_addr)); if (bind(s, (struct sockaddr *)&src, sizeof(struct sockaddr_in6)) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "bind: %s", strerror(errno)); close(s); return(BAD); } memset((char *) &dst, 0, sizeof(struct sockaddr_in6)); dst.sin6_family = AF_INET6; dst.sin6_port = htons(dst_port); memcpy(&dst.sin6_addr,&(dst_addr->address.ipv6),sizeof(struct in6_addr)); if ((nbytes = sendto(s, (const void *) packet, packet_len, 0, (struct sockaddr *)&dst, sizeof(struct sockaddr_in6))) < 0) { LISPD_LOG(LISP_LOG_DEBUG_2, "sendto: %s", strerror(errno)); close(s); return(BAD); } if (nbytes != packet_len) { LISPD_LOG(LISP_LOG_DEBUG_2, "nbytes (%d) != packet (%d)\n", nbytes, packet_len); close(s); return(BAD); } close(s); return (GOOD); }
//add by csq // static int raopcl_stream_connect_udp(raopcl_data_t *raopcld){ __u16 myport=0; if((raopcld->sfd=open_udp_socket(NULL,&myport))==-1)return -1; if(get_udp_connect_by_host(raopcld->sfd,raopcld->addr, rtspcl_get_server_port(raopcld->rtspcl))){ close(raopcld->sfd); raopcld->sfd=-1; return -1; } return 0; }
int open_input_socket(int afi, int port){ struct sockaddr_in sock_addr_v4; struct sockaddr_in6 sock_addr_v6; struct sockaddr *sock_addr; int sock_addr_len; int sock; sock = open_udp_socket(afi); if(sock == BAD){ return BAD; } switch (afi){ case AF_INET: memset(&sock_addr_v4,0,sizeof(sock_addr_v4)); /* be sure */ sock_addr_v4.sin_port = htons(port); sock_addr_v4.sin_family = AF_INET; sock_addr_v4.sin_addr.s_addr = INADDR_ANY; sock_addr = (struct sockaddr *) &sock_addr_v4; sock_addr_len = sizeof(sock_addr_v4); break; case AF_INET6: memset(&sock_addr_v6,0,sizeof(sock_addr_v6)); /* be sure */ sock_addr_v6.sin6_family = AF_INET6; sock_addr_v6.sin6_port = htons(port); sock_addr_v6.sin6_addr = in6addr_any; sock_addr = (struct sockaddr *) &sock_addr_v6; sock_addr_len = sizeof(sock_addr_v6); break; default: return BAD; } if (bind(sock,sock_addr, sock_addr_len) == -1) { syslog(LOG_DAEMON, "bind input socket: %s", strerror(errno)); return(BAD); } return sock; }
/***************************************************************************** * @name * @description * @param * @return */ void init_sip_session(sip_session_t *session) { session->call = NULL; session->seq = 1; session->curr_state = REGISTERING; session->prev_state = INIT; session->socket = open_udp_socket(session->localip, session->localport); send_sip_register(session, DEFAULT_EXPIRATION); }
int open_data_input_socket(int afi){ int sock = 0; int dummy_sock = 0; /* To avoid ICMP port unreacheable packets */ const int on = 1; sock = open_raw_input_socket(afi); dummy_sock = open_udp_socket(afi); dummy_sock = bind_socket(dummy_sock,afi,LISP_DATA_PORT); if(sock == BAD){ return(BAD); } switch (afi){ case AF_INET: /* IP_RECVTOS is requiered to get later the IPv4 original TOS */ if(setsockopt(sock, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on))< 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IP_RECVTOS: %s", strerror(errno)); } /* IP_RECVTTL is requiered to get later the IPv4 original TTL */ if(setsockopt(sock, IPPROTO_IP, IP_RECVTTL, &on, sizeof(on))< 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IP_RECVTTL: %s", strerror(errno)); } break; case AF_INET6: /* IPV6_RECVTCLASS is requiered to get later the IPv6 original TOS */ if(setsockopt(sock, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on))< 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IPV6_RECVTCLASS: %s", strerror(errno)); } /* IPV6_RECVHOPLIMIT is requiered to get later the IPv6 original TTL */ if(setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof(on))< 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IPV6_RECVHOPLIMIT: %s", strerror(errno)); } break; default: return(BAD); } return(sock); }
/* Init eap socket */ int wps_osl_eap_handle_init() { int handle; /* open socket */ handle = open_udp_socket(WPS_EAP_ADDR, EAPD_WKSP_WPS_UDP_MPORT); if (handle < 0) { TUTRACE((TUTRACE_ERR, "init eap handle error\n")); return -1; } return handle; }
/* Init ui socket */ int wps_osl_ui_handle_init() { int handle; /* open socket */ handle = open_udp_socket(WPS_UI_ADDR, WPS_UI_PORT); if (handle < 0) { TUTRACE((TUTRACE_ERR, "init ui handle error\n")); return -1; } return handle; }
static void run(Options *options) { int socket = open_udp_socket(options->listen_port); if (options->verbose) fprintf(stderr, "Opened socket on port %d\n", options->listen_port); if (signal(SIGQUIT, handle_sigquit) == SIG_IGN) signal(SIGQUIT, SIG_IGN); reload_config = 1; while (1) { int sleep_time; if (reload_config) { if (options->config != NULL) destroy_config(options->config); options->config = load_config(options->config_filename); if (!options->config) { fprintf(stderr, "Warning: Config file cannot be read: %s\n", options->config_filename); options->config = create_config(); } initialise_config(options->config); if (options->verbose) { fprintf(stderr, "Loaded config from %s\n", options->config_filename); print_config(options->config, stderr); } reload_config = 0; } //TODO how long until the next request goes out? sleep_time = 1; input_timeout(socket, sleep_time); check_for_responses(options, socket); check_requests(options, socket); } close(socket); }
static int raopcl_stream_connect(raopcl_data_t *raopcld) { u_int16_t myport=0; if((raopcld->sfd=open_tcp_socket(NULL, &myport))==-1) return -1; if(get_tcp_connect_by_host(raopcld->sfd, raopcld->addr, rtspcl_get_server_port(raopcld->rtspcl))) { close(raopcld->sfd); if((raopcld->sfd=open_udp_socket(NULL, &myport))==-1) return -1; if(get_tcp_connect_by_host(raopcld->sfd, raopcld->addr, rtspcl_get_server_port(raopcld->rtspcl))) { ERRMSG("%s: connect failed\n", __func__); close(raopcld->sfd); raopcld->sfd=-1; return -1; } else printf("RAOP stream connected via UDP\n"); } else printf("RAOP stream connected via TCP\n"); return 0; }
int open_control_input_socket(int afi){ const int on = 1; int sock = 0; sock = open_udp_socket(afi); sock = bind_socket(sock,afi,LISP_CONTROL_PORT); if(sock == BAD){ return (BAD); } switch (afi){ case AF_INET: /* IP_PKTINFO is requiered to get later the IPv4 destination address of incoming control packets*/ if(setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on))< 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IP_PKTINFO: %s", strerror(errno)); } break; case AF_INET6: /* IPV6_RECVPKTINFO is requiered to get later the IPv6 destination address of incoming control packets*/ if(setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on)) < 0){ LISPD_LOG(LISP_LOG_WARNING, "setsockopt IPV6_RECVPKTINFO: %s", strerror(errno)); } break; default: return(BAD); } return(sock); }
/***************************************************************************** * @name * @description * @param * @return */ void handle_sip_msg(sip_session_t *session, char *str) { int l; char *s; sip_msg_t *msg; struct sockaddr_in addr; msg = read_sip_msg(str); switch(session->curr_state) { case REGISTERING: if(msg->type == ANSWER && msg->code >= 200 && msg->code < 300) { fprintf(stdout,"Registo efectuado com sucesso.\n"); session->prev_state = REGISTERING; session->curr_state = REGISTERED; } else if(msg->type == ANSWER && msg->code < 100 && msg->code > 200) { fprintf(stdout,"Registo não efectuado.\n"); exit(1); } free_sip_call(msg->call); break; case REGISTERED: if(msg->type == REQUEST && !strcmp(msg->method,"INVITE") && msg->contact != NULL) { session->call = msg->call; session->seq = msg->cseq; session->call->sport = ntohs(addr.sin_port); session->call->addr.sin_family = AF_INET; session->call->addr.sin_addr.s_addr = inet_addr(session->call->dip); session->call->addr.sin_port = htons(session->call->dport); session->call->rtp_session.nseqpkt = 0; session->call->rtp_session.firstpkt = TRUE; session->call->socket = open_udp_socket(session->localip,session->call->sport); l = sizeof(addr); //if(getsockname(session->call->socket, (struct sockaddr *) &addr, (socklen_t *) &l)) die_with_error("getsockname() //failed"); s = mk_sip_msg(session, DEFAULT_EXPIRATION, INVITE_OK); if((l = sendto(session->socket,s,strlen(s)+1,0,(struct sockaddr *) &(session->addr), sizeof(session->addr))) != strlen(s)+1) die_with_error("sendto() failed"); session->prev_state = REGISTERED; session->curr_state = INVITED; } break; case INVITING: if(msg->type == ANSWER && msg->code >= 200 && msg->code < 300) { printf("ACK\n"); session->call->dport = msg->call->dport; session->call->tag = (char *) malloc((strlen(msg->call->tag)+1)*sizeof(char)); memset(session->call->tag,'\0',strlen(msg->call->tag)+1); memcpy(session->call->tag,msg->call->tag,strlen(msg->call->tag)); session->call->addr.sin_family = AF_INET; session->call->addr.sin_addr.s_addr = inet_addr(session->call->dip); session->call->addr.sin_port = htons(session->call->dport); s = mk_sip_msg(session, DEFAULT_EXPIRATION, ACK); if((l = sendto(session->socket,s,strlen(s)+1,0,(struct sockaddr *) &(session->addr), sizeof(session->addr))) != strlen(s)+1) die_with_error("sendto() failed"); free_sip_call(msg->call); session->prev_state = INVITING; session->curr_state = ONCALL; } else if(msg->type == ANSWER && msg->code == 404) { session->call->tag = (char *) malloc((strlen(msg->call->tag)+1)*sizeof(char)); memset(session->call->tag,'\0',strlen(msg->call->tag)+1); memcpy(session->call->tag,msg->call->tag,strlen(msg->call->tag)); //session->call->addr.sin_family = AF_INET; //session->call->addr.sin_addr.s_addr = inet_addr(session->call->dip); //session->call->addr.sin_port = htons(session->call->dport); s = mk_sip_msg(session, DEFAULT_EXPIRATION, ACK); if((l = sendto(session->socket,s,strlen(s)+1,0,(struct sockaddr *) &(session->addr), sizeof(session->addr))) != strlen(s)+1) die_with_error("sendto() failed"); free_sip_call(msg->call); free_sip_call(session->call); session->call = NULL; fprintf(stdout,"\nNão foi encontrada nenhuma aplicação VoIP no destino.\n"); session->prev_state = INVITING; session->curr_state = REGISTERED; } break; case INVITED: if(msg->type == REQUEST && !strcmp(msg->method,"ACK")) { session->prev_state = INVITED; session->curr_state = ONCALL; } free_sip_call(msg->call); break; case ONCALL: if(msg->type == REQUEST && !strcmp(msg->method,"BYE")) { session->seq = msg->cseq; s = mk_sip_msg(session, DEFAULT_EXPIRATION, BYE_OK); if((l = sendto(session->socket,s,strlen(s)+1,0,(struct sockaddr *) &(session->addr), sizeof(session->addr))) != strlen(s)+1) die_with_error("sendto() failed"); close(session->call->socket); free_sip_call(session->call); session->call = NULL; free_sip_call(msg->call); session->prev_state = ONCALL; session->curr_state = REGISTERED; } break; case BYE: if(msg->type == ANSWER && msg->code >= 200 && msg->code < 300) { session->prev_state = BYE; session->curr_state = REGISTERED; free_sip_call(msg->call); free_sip_call(session->call); session->call = NULL; } break; case UNREGISTERING: if(msg->type == ANSWER && msg->code >= 200 && msg->code < 300) { session->prev_state = REGISTERED; session->curr_state = UNREGISTERED; free_sip_call(msg->call); } break; } free_sip_msg(msg); }
int main (int argc, char **argv) { struct option long_options[] = { {"intf", 1, 0, 'i'}, {"port", 1, 0, 'p'}, {"verbose", 0, 0, 'v'}, {"json", 0, 0, 'j'}, {"help", 0, 0, 'h'}, {NULL, 0, 0, 0} }; struct sockaddr_ll fout; int fsock = 0, usock = 0; int verbose = 0, a2i, c, i; unsigned short port = 8159; const char *intf; char *end; while (1) { c = getopt_long (argc, argv, "i:p:vjh", long_options, &i); if (c == -1) { break; } switch (c) { case 'i': intf = optarg; break; case 'p': a2i = strtol (optarg, &end, 10); if (errno == ERANGE && (a2i == LONG_MAX || a2i == LONG_MIN)) { fprintf (stderr, "Unable to parse the port parameter\n"); exit(-1); } port = a2i; break; case 'v': if (!verbose) verbose = TEXT_OUTPUT; break; case 'j': verbose = JSON_OUTPUT; break; case 'h': default: usage (argv[0]); } } if ((usock = open_udp_socket (port)) == -1) { fprintf (stderr, "Unable to open the listening udp port: %s\n", strerror (errno)); exit (-1); } if (intf != NULL) { if ((fsock = open_forward_socket (intf, &fout)) == -1) { fprintf (stderr, "Unable to open the forward interface: %s\n", strerror (errno)); exit (-1); } } forward (usock, fsock, &fout, verbose); return -1; }
static ADS_STATUS do_krb5_kpasswd_request(krb5_context context, const char *kdc_host, uint16 pversion, krb5_creds *credsp, const char *princ, const char *newpw) { krb5_auth_context auth_context = NULL; krb5_data ap_req, chpw_req, chpw_rep; int ret, sock; socklen_t addr_len; struct sockaddr_storage remote_addr, local_addr; struct sockaddr_storage addr; krb5_address local_kaddr, remote_kaddr; bool use_tcp = False; if (!interpret_string_addr(&addr, kdc_host, 0)) { } ret = krb5_mk_req_extended(context, &auth_context, AP_OPTS_USE_SUBKEY, NULL, credsp, &ap_req); if (ret) { DEBUG(1,("krb5_mk_req_extended failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } do { if (!use_tcp) { sock = open_udp_socket(kdc_host, DEFAULT_KPASSWD_PORT); if (sock == -1) { int rc = errno; SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("failed to open kpasswd socket to %s " "(%s)\n", kdc_host, strerror(errno))); return ADS_ERROR_SYSTEM(rc); } } else { NTSTATUS status; status = open_socket_out(&addr, DEFAULT_KPASSWD_PORT, LONG_CONNECT_TIMEOUT, &sock); if (!NT_STATUS_IS_OK(status)) { SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("failed to open kpasswd socket to %s " "(%s)\n", kdc_host, nt_errstr(status))); return ADS_ERROR_NT(status); } } addr_len = sizeof(remote_addr); if (getpeername(sock, (struct sockaddr *)&remote_addr, &addr_len) != 0) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("getpeername() failed (%s)\n", error_message(errno))); return ADS_ERROR_SYSTEM(errno); } addr_len = sizeof(local_addr); if (getsockname(sock, (struct sockaddr *)&local_addr, &addr_len) != 0) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("getsockname() failed (%s)\n", error_message(errno))); return ADS_ERROR_SYSTEM(errno); } if (!setup_kaddr(&remote_kaddr, &remote_addr) || !setup_kaddr(&local_kaddr, &local_addr)) { DEBUG(1,("do_krb5_kpasswd_request: " "Failed to setup addresses.\n")); close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); errno = EINVAL; return ADS_ERROR_SYSTEM(EINVAL); } ret = krb5_auth_con_setaddrs(context, auth_context, &local_kaddr, NULL); if (ret) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("krb5_auth_con_setaddrs failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = build_kpasswd_request(pversion, context, auth_context, &ap_req, princ, newpw, use_tcp, &chpw_req); if (ret) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("build_setpw_request failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = write(sock, chpw_req.data, chpw_req.length); if (ret != chpw_req.length) { close(sock); SAFE_FREE(chpw_req.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("send of chpw failed (%s)\n", strerror(errno))); return ADS_ERROR_SYSTEM(errno); } SAFE_FREE(chpw_req.data); chpw_rep.length = 1500; chpw_rep.data = (char *) SMB_MALLOC(chpw_rep.length); if (!chpw_rep.data) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("send of chpw failed (%s)\n", strerror(errno))); errno = ENOMEM; return ADS_ERROR_SYSTEM(errno); } ret = read(sock, chpw_rep.data, chpw_rep.length); if (ret < 0) { close(sock); SAFE_FREE(chpw_rep.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("recv of chpw reply failed (%s)\n", strerror(errno))); return ADS_ERROR_SYSTEM(errno); } close(sock); chpw_rep.length = ret; ret = krb5_auth_con_setaddrs(context, auth_context, NULL,&remote_kaddr); if (ret) { SAFE_FREE(chpw_rep.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("krb5_auth_con_setaddrs on reply failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = parse_setpw_reply(context, use_tcp, auth_context, &chpw_rep); SAFE_FREE(chpw_rep.data); if (ret) { if (ret == KRB5KRB_ERR_RESPONSE_TOO_BIG && !use_tcp) { DEBUG(5, ("Trying setpw with TCP!!!\n")); use_tcp = True; continue; } SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("parse_setpw_reply failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); } while ( ret ); return ADS_SUCCESS; }
int main(int argc, char **argv) { enum state state; unsigned char command; struct timeval tval; struct packet pkt; /* Open a socket and start listening to a scpefied port */ open_udp_socket(); srand(time(NULL)); /* Startup: */ build_send_packet(BROADCAST, CMD_MASTERREQ, 0); /* Search for a master */ change_state(&state, STATE_STARTUP, &tval, NULL); for(;;) { struct timeval curtime; gettimeofday(&curtime, NULL); printf(" "); print_time(&curtime); /*printf(" TIME: %10d sec %10d usec\n", (unsigned int)curtime.tv_sec, (unsigned int)curtime.tv_usec);*/ recv_msg(&pkt, &tval); command = pkt.type; //printf("Command received = %d\n", command); switch(state | command) { /* STARTUP */ case(STATE_STARTUP | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_MASTERUP, 0); change_state(&state, STATE_MASTER, &tval, &master_timeout); break; case(STATE_STARTUP | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_SLAVEUP, 0); // no break; case(STATE_STARTUP | CMD_MASTERREQ): case(STATE_STARTUP | CMD_MASTERACK): case(STATE_STARTUP | CMD_ELECTION): change_state(&state, STATE_SLAVE, &tval, NULL); break; /* MASTER */ /* Launch a new thread and process separately? Prevents loss of messages */ case(STATE_MASTER | CMD_TIMEOUT): /* Does the Master needs to send his clock? */ build_send_packet(BROADCAST, CMD_CLOCKREQ, 1); //change_state(&state, STATE_MASTER, &tval, MASTER_TIMEOUT); /* Change to an intermediate state in order to wait for all slaves * to send their clocks. After the MASTER_ADJTIME_TIMEOUT no more clock * packets will be accepted and the "slow" slaves, if any, won't * be synchronized*/ change_state(&state, STATE_MASTER_ADJTIME, &tval, &master_adjtime_timeout); /* Possibly new thread? Non blocking function...*/ adjust_master_prepare(); break; case(STATE_MASTER | CMD_MASTERREQ): build_send_packet(pkt.ip, CMD_MASTERACK, 0); break; case(STATE_MASTER | CMD_QUIT): build_send_packet(pkt.ip, CMD_ACK, 0); change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_MASTER | CMD_ELECTION): case(STATE_MASTER | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_QUIT, 0); break; /* MASTER_ADJTIME */ case(STATE_MASTER_ADJTIME | CMD_CLOCKREQ_RESPONSE): /* Got time from client */ adjust_master_addslave(pkt.ip, &pkt.time); break; case(STATE_MASTER_ADJTIME | CMD_TIMEOUT): /* Calculate avg clocks and send to each slave his correction */ /* Restart the synchronization timer */ change_state(&state, STATE_MASTER, &tval, &master_timeout); adjust_master_calcandsend(); break; /* SLAVE */ case(STATE_SLAVE | CMD_CLOCKREQ): /* Send clock packet to master and change to an intermediate state * in order to wait for a synch packet */ build_send_packet(pkt.ip, CMD_CLOCKREQ_RESPONSE, 1); change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_SLAVE | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_ELECTION, 0); change_state(&state, STATE_CANDIDATE, &tval, &candidate_timeout); break; case(STATE_SLAVE | CMD_MASTERUP): build_send_packet(BROADCAST, CMD_SLAVEUP, 0); break; case(STATE_SLAVE | CMD_ELECTION): build_send_packet(pkt.ip, CMD_ACCEPT, 0); change_state(&state, STATE_ACCEPT, &tval, &accept_timeout); break; case(STATE_SLAVE | CMD_CLOCKSYNC): /* Receive packet from master, adjust local time and return to * your rightful state (slave of course... =])*/ adjust_slave_clock(&pkt.time); change_state(&state, STATE_SLAVE, &tval, NULL); break; /* CANDIDATE */ case(STATE_CANDIDATE | CMD_TIMEOUT): build_send_packet(BROADCAST, CMD_MASTERUP, 0); change_state(&state, STATE_MASTER, &tval, &master_timeout); break; case(STATE_CANDIDATE | CMD_ELECTION): build_send_packet(pkt.ip, CMD_REFUSE, 0); break; case(STATE_CANDIDATE | CMD_ACCEPT): build_send_packet(pkt.ip, CMD_ACK, 0); break; case(STATE_CANDIDATE | CMD_QUIT): case(STATE_CANDIDATE | CMD_REFUSE): build_send_packet(pkt.ip, CMD_ACK, 0); //no break case(STATE_CANDIDATE | CMD_MASTERREQ): change_state(&state, STATE_SLAVE, &tval, NULL); break; /* ACCEPT */ case(STATE_ACCEPT | CMD_TIMEOUT): change_state(&state, STATE_SLAVE, &tval, NULL); break; case(STATE_ACCEPT | CMD_ELECTION): build_send_packet(pkt.ip, CMD_REFUSE, 0); break; case(STATE_ACCEPT | CMD_MASTERUP): build_send_packet(pkt.ip, CMD_SLAVEUP, 0); break; } } return 0; }
int main(int argc, char *argv[]) { // Handle signals signal(SIGINT,shut_down); signal(SIGHUP,shut_down); signal(SIGTERM,shut_down); signal(SIGQUIT,shut_down); // HCI device number, MAC struct int device = 0; bdaddr_t bdaddr; bacpy(&bdaddr, BDADDR_ANY); // Time to scan. Scan time is roughly 1.28 seconds * scan_window // Originally this was always 8, now we adjust based on device: #ifdef OPENWRT int scan_window = 8; #elif PWNPLUG int scan_window = 5; #else int scan_window = 3; #endif // Maximum number of devices per scan int max_results = 255; int num_results; // Device cache and index int cache_index = 0; // HCI cache setting int flags = IREQ_CACHE_FLUSH; // Strings to hold MAC and name char addr[19] = {0}; char addr_buff[19] = {0}; // String for time char cur_time[20]; // Process ID read from PID file int ext_pid; // Pointers to filenames char *infofilename = LIVE_INF; // Change default filename based on date char OUT_FILE[1000] = OUT_PATH; strncat(OUT_FILE, file_timestamp(),sizeof(OUT_FILE)-strlen(OUT_FILE)-1); char *outfilename = OUT_FILE; // Mode to open output file in char *filemode = "a+"; // Output buffer char outbuffer[500]; // Buffer for data from the second loop char exitbuffer[500]; // Misc Variables int i, ri, opt; // Record numbner of BlueZ errors int error_count = 0; // Current epoch time long long int epoch; // Kernel version info struct utsname sysinfo; uname(&sysinfo); while ((opt=getopt_long(argc,argv,"+o:i:r:a:w:vxctghldbfenksmq", main_options, NULL)) != EOF) { switch (opt) { case 'i': if (!strncasecmp(optarg, "hci", 3)) hci_devba(atoi(optarg + 3), &bdaddr); else str2ba(optarg, &bdaddr); break; case 'o': outfilename = strdup(optarg); break; case 'r': config.retry_count = atoi(optarg); break; case 'a': config.amnesia = atoi(optarg); break; case 'w': config.scan_window = round((atoi(optarg) / 1.28)); break; case 'c': config.showclass = 1; break; case 'e': config.encode = 1; break; case 'f': config.friendlyclass = 1; break; case 'v': config.verbose = 1; break; case 'g': config.status = 1; break; case 't': config.showtime = 1; break; case 's': config.syslogonly = 1; break; case 'x': config.obfuscate = 1; break; case 'q': config.quiet = 1; break; case 'l': if(!LIVEMODE) { printf("Live mode has been disabled in this build. See documentation.\n"); exit(0); } else config.bluelive = 1; break; case 'b': config.bluepropro = 1; break; case 'd': config.daemon = 1; break; case 'n': config.getname = 1; break; case 'm': if(!OUILOOKUP) { printf("Manufacturer lookups have been disabled in this build. See documentation.\n"); exit(0); } else config.getmanufacturer = 1; break; case 'h': help(); exit(0); case 'k': // Read PID from file into variable ext_pid = read_pid(); if (ext_pid != 0) { printf("Killing Bluelog process with PID %i...",ext_pid); if(kill(ext_pid,15) != 0) { printf("ERROR!\n"); printf("Unable to kill Bluelog process. Check permissions.\n"); exit(1); } else printf("OK.\n"); // Delete PID file unlink(PID_FILE); } else printf("No running Bluelog process found.\n"); exit(0); default: printf("Unknown option. Use -h for help, or see README.\n"); exit(1); } } // See if there is already a process running if (read_pid() != 0) { printf("Another instance of Bluelog is already running!\n"); printf("Use the -k option to kill a running Bluelog process.\n"); exit(1); } // Load config from file if no options given on command line if(cfg_exists() && argc == 1) { if (cfg_read() != 0) { printf("Error opening config file!\n"); exit(1); } // Put interface into BT struct hci_devba(config.hci_device, &bdaddr); } // Perform sanity checks on varibles cfg_check(); // Setup libmackerel mac_init(); // Boilerplate if (!config.quiet) { printf("%s (v%s%s) by MS3FGX\n", APPNAME, VERSION, VER_MOD); #if defined OPENWRT || PWNPLUG printf("----"); #endif printf("---------------------------\n"); } // Show notification we loaded config from file if(cfg_exists() && argc == 1 && !config.quiet) printf("Config loaded from: %s\n", CFG_FILE); // Init Hardware ba2str(&bdaddr, config.addr); if (!strcmp(config.addr, "00:00:00:00:00:00")) { if (!config.quiet) printf("Autodetecting device..."); device = hci_get_route(NULL); // Put autodetected device MAC into addr hci_devba(device, &bdaddr); ba2str(&bdaddr, config.addr); } else { if (!config.quiet) printf("Initializing device..."); device = hci_devid(config.addr); } // Open device and catch errors config.bt_socket = hci_open_dev(device); if (device < 0 || config.bt_socket < 0) { // Failed to open device, that can't be good printf("\n"); printf("Error initializing Bluetooth device!\n"); exit(1); } // If we get here the device should be online. if (!config.quiet) printf("OK\n"); // Status message for BPP if (!config.quiet) if (config.bluepropro) printf("Output formatted for BlueProPro.\n" "More Info: www.hackfromacave.com\n"); // Open socket if (config.udponly) open_udp_socket(); // Open output file, unless in networking mode if (!config.syslogonly && !config.udponly) { if (config.bluelive) { // Change location of output file outfilename = LIVE_OUT; filemode = "w"; if (!config.quiet) printf("Starting Bluelog Live...\n"); } if (!config.quiet) printf("Opening output file: %s...", outfilename); if ((outfile = fopen(outfilename, filemode)) == NULL) { printf("\n"); printf("Error opening output file!\n"); exit(1); } if (!config.quiet) printf("OK\n"); } else if (!config.quiet) printf("Network mode enabled, not creating log file.\n"); // Open status file if (config.bluelive) { if (!config.quiet) printf("Opening info file: %s...", infofilename); if ((infofile = fopen(infofilename,"w")) == NULL) { printf("\n"); printf("Error opening info file!\n"); exit(1); } if (!config.quiet) printf("OK\n"); } // Write PID file if (!config.daemon) write_pid(getpid()); // Get and print time to console and file strcpy(cur_time, get_localtime()); if (!config.daemon) printf("Scan started at [%s] on %s\n", cur_time, config.addr); if (config.showtime && (outfile != NULL)) { fprintf(outfile,"[%s] Scan started on %s\n", cur_time, config.addr); // Make sure this gets written out fflush(outfile); } // Write info file for Bluelog Live if (config.bluelive) { fprintf(infofile,"<div class=\"sideitem\">%s Version: %s%s</div>\n", APPNAME, VERSION, VER_MOD); fprintf(infofile,"<div class=\"sideitem\">Device: %s</div>\n", config.addr); fprintf(infofile,"<div class=\"sideitem\">Started: %s</div>\n", cur_time); // Think we are done with you now fclose(infofile); } // Log success to this point syslog(LOG_INFO,"Init OK!"); // Daemon switch if (config.daemon) daemonize(); else if (!config.quiet) #if defined PWNPAD printf("Close this window to end scan.\n"); #else printf("Hit Ctrl+C to end scan.\n"); #endif // Init result struct results = (inquiry_info*)malloc(max_results * sizeof(inquiry_info)); // Start scan, be careful with this infinite loop... for(;;) { // Flush results buffer memset(results, '\0', max_results * sizeof(inquiry_info)); // Scan and return number of results num_results = hci_inquiry(device, scan_window, max_results, NULL, &results, flags); // A negative number here means an error during scan if(num_results < 0) { // Increment error count error_count++; // Ignore occasional errors on Pwn Plug and OpenWRT #if !defined PWNPLUG || OPENWRT // All other platforms, print error and bail out syslog(LOG_ERR,"Received error from BlueZ!"); printf("Scan failed!\n"); // Check for kernel 3.0.x if (!strncmp("3.0.",sysinfo.release,4)) { printf("\n"); printf("-----------------------------------------------------\n"); printf("Device scanning failed, and you are running a 3.0.x\n"); printf("Linux kernel. This failure is probably due to the\n"); printf("following kernel bug:\n"); printf("\n"); printf("http://marc.info/?l=linux-kernel&m=131629118406044\n"); printf("\n"); printf("You will need to upgrade your kernel to at least the\n"); printf("the 3.1 series to continue.\n"); printf("-----------------------------------------------------\n"); } shut_down(1); #else // Exit on back to back errors if (error_count > 5) { printf("Scan failed!\n"); syslog(LOG_ERR,"BlueZ not responding, unrecoverable!"); shut_down(1); } // Otherwise, throttle back a bit, might help sleep(1); #endif } else { // Clear error counter error_count = 0; } // Check if we need to reset device cache if ((cache_index + num_results) >= MAX_DEV) { syslog(LOG_INFO,"Resetting device cache..."); memset(dev_cache, 0, sizeof(dev_cache)); cache_index = 0; } // Loop through results for (i = 0; i < num_results; i++) { // Return current MAC from struct ba2str(&(results+i)->bdaddr, addr); // Compare to device cache for (ri = 0; ri <= cache_index; ri++) { // Determine if device is already logged if (strcmp (addr, dev_cache[ri].priv_addr) == 0) { // This device has been seen before // Increment seen count, update printed time dev_cache[ri].seen++; strcpy(dev_cache[ri].time, get_localtime()); dev_cache[ri].missing_count = 0; // If we don't have a name, query again if ((dev_cache[ri].print == 3) && (dev_cache[ri].seen > config.retry_count)) { syslog(LOG_INFO,"Unable to find name for %s!", addr); dev_cache[ri].print = 1; } else if ((dev_cache[ri].print == 3) && (dev_cache[ri].seen < config.retry_count)) { // Query name strcpy(dev_cache[ri].name, namequery(&(results+i)->bdaddr)); // Did we get one? if (strcmp (dev_cache[ri].name, "VOID") != 0) { syslog(LOG_INFO,"Name retry for %s successful!", addr); // Force print dev_cache[ri].print = 1; } else syslog(LOG_INFO,"Name retry %i for %s failed!",dev_cache[ri].seen, addr); } // Amnesia mode if (config.amnesia >= 0) { // Find current epoch time epoch = time(NULL); if ((epoch - dev_cache[ri].epoch) >= (config.amnesia * 60)) { // Update epoch time dev_cache[ri].epoch = epoch; // Set device to print dev_cache[ri].print = 1; } } // This device is seen before, but has been away if (strcmp (dev_cache[ri].status, "gone") == 0) { dev_cache[ri].print = 1; strcpy(dev_cache[ri].status, "returned"); } // Unless we need to get printed, move to next result if (dev_cache[ri].print != 1) break; } else if (strcmp (dev_cache[ri].addr, "") == 0) { // Write new device MAC (visible and internal use) strcpy(dev_cache[ri].addr, addr); strcpy(dev_cache[ri].priv_addr, addr); // Query for name if (config.getname) strcpy(dev_cache[ri].name, namequery(&(results+i)->bdaddr)); else strcpy(dev_cache[ri].name, "IGNORED"); // Get time found strcpy(dev_cache[ri].time, get_localtime()); dev_cache[ri].epoch = time(NULL); // Class info dev_cache[ri].flags = (results+i)->dev_class[2]; dev_cache[ri].major_class = (results+i)->dev_class[1]; dev_cache[ri].minor_class = (results+i)->dev_class[0]; // Init misc variables dev_cache[ri].seen = 1; dev_cache[ri].missing_count = 0; strcpy(dev_cache[ri].status, "new"); // Increment index cache_index++; // If we have a device name, get printed if (strcmp (dev_cache[ri].name, "VOID") != 0) dev_cache[ri].print = 1; else { // Found with no name. // Print message to syslog, prevent printing, and move on syslog(LOG_INFO,"Device %s discovered with no name, will retry", dev_cache[ri].addr); dev_cache[ri].print = 3; break; } } // Ready to print? if (dev_cache[ri].print == 1) { // Encode MAC if (config.encode || config.obfuscate) { // Clear buffer memset(addr_buff, '\0', sizeof(addr_buff)); if (config.obfuscate) strcpy(addr_buff, mac_obfuscate(dev_cache[ri].priv_addr)); if (config.encode) strcpy(addr_buff, mac_encode(dev_cache[ri].priv_addr)); // Copy to cache strcpy(dev_cache[ri].addr, addr_buff); } // Print everything to console if verbose is on, optionally friendly class info if (config.verbose) { if (config.friendlyclass) { printf("[%s] %s,%s,%s,(%s) - %s\n",\ dev_cache[ri].time, dev_cache[ri].addr,\ dev_cache[ri].name, device_class(dev_cache[ri].major_class,\ dev_cache[ri].minor_class), device_capability(dev_cache[ri].flags), dev_cache[ri].status); } else { printf("[%s] %s,%s,0x%02x%02x%02x - %s\n",\ dev_cache[ri].time, dev_cache[ri].addr,\ dev_cache[ri].name, dev_cache[ri].flags,\ dev_cache[ri].major_class, dev_cache[ri].minor_class, dev_cache[ri].status); } } if (config.bluelive) { // Write result with live function live_entry(ri); } else if (config.bluepropro) { // Set output format for BlueProPro fprintf(outfile,"%s", dev_cache[ri].addr); fprintf(outfile,",0x%02x%02x%02x", dev_cache[ri].flags,\ dev_cache[ri].major_class, dev_cache[ri].minor_class); fprintf(outfile,",%s\n", dev_cache[ri].name); } else { // Flush buffer memset(outbuffer, 0, sizeof(outbuffer)); // Print time first if enabled if (config.showtime) sprintf(outbuffer,"[%s],", dev_cache[ri].time); // Always output MAC sprintf(outbuffer+strlen(outbuffer),"%s", dev_cache[ri].addr); // Optionally output class if (config.showclass) sprintf(outbuffer+strlen(outbuffer),",0x%02x%02x%02x", dev_cache[ri].flags,\ dev_cache[ri].major_class, dev_cache[ri].minor_class); // "Friendly" version of class info if (config.friendlyclass) sprintf(outbuffer+strlen(outbuffer),",%s,(%s)",\ device_class(dev_cache[ri].major_class, dev_cache[ri].minor_class),\ device_capability(dev_cache[ri].flags)); // Get manufacturer if (config.getmanufacturer) sprintf(outbuffer+strlen(outbuffer),",%s", mac_get_vendor(dev_cache[ri].priv_addr)); // Append the name if (config.getname) sprintf(outbuffer+strlen(outbuffer),",%s", dev_cache[ri].name); // Append the status if (config.status) sprintf(outbuffer+strlen(outbuffer)," - %s", dev_cache[ri].status); // Send buffer, else file. File needs newline if (config.syslogonly) syslog(LOG_INFO,"%s", outbuffer); else if (config.udponly) { // Append newline to socket, kind of hacky sprintf(outbuffer+strlen(outbuffer),"\n"); send_udp_msg(outbuffer); } else fprintf(outfile,"%s\n",outbuffer); } dev_cache[ri].print = 0; break; } // If we make it this far, it means we will check next stored device } // If there's a file open, write changes if (outfile != NULL) fflush(outfile); } // Now check if any devices are missing // Loop through the cache for (ri = 0; ri < cache_index; ri++) { for (i = 0; i <= num_results; i++) { // Return current MAC from struct ba2str(&(results+i)->bdaddr, addr); // Determine if device still present if (strcmp (addr, dev_cache[ri].priv_addr) == 0) { break; } // Device not found. if (i == num_results) { // The device is missing but not marked as gone -> it has just disappeared if (strcmp(dev_cache[ri].status, "gone") != 0) { // Devices aren't present every time. Wait a while before marking it gone if (dev_cache[ri].missing_count < 10) { dev_cache[ri].missing_count++; } else // It's really gone :( { strcpy(dev_cache[ri].status,"gone"); // Print to console if (config.verbose) { printf("[%s] %s,%s - %s\n",\ dev_cache[ri].time, dev_cache[ri].addr,\ dev_cache[ri].name, dev_cache[ri].status); } // Flush buffer memset(exitbuffer, 0, sizeof(exitbuffer)); // Print time first if enabled if (config.showtime) sprintf(exitbuffer,"[%s],", dev_cache[ri].time); // Always output MAC sprintf(exitbuffer+strlen(exitbuffer),"%s", dev_cache[ri].addr); // Append the name if (config.getname) sprintf(exitbuffer+strlen(exitbuffer),",%s", dev_cache[ri].name); // Append the status if (config.status) sprintf(exitbuffer+strlen(exitbuffer)," - %s", dev_cache[ri].status); // Send buffer, else file. File needs newline if (config.syslogonly) syslog(LOG_INFO,"%s", exitbuffer); else if (config.udponly) { // Append newline to socket, kind of hacky sprintf(exitbuffer+strlen(exitbuffer),"\n"); send_udp_msg(exitbuffer); } else fprintf(outfile,"%s\n",exitbuffer); // If there's a file open, write changes if (outfile != NULL) fflush(outfile); } } } } } } // If we get here, shut down shut_down(0); // STFU return (1); }
/* do a cldap netlogon query */ int ads_cldap_netlogon(ADS_STRUCT *ads) { int sock; int ret; struct cldap_netlogon_reply reply; const char *target = opt_host ? opt_host : inet_ntoa(ads->ldap_ip); sock = open_udp_socket(target, ads->ldap_port); if (sock == -1) { d_printf("Failed to open udp socket to %s:%u\n", inet_ntoa(ads->ldap_ip), ads->ldap_port); return -1; } ret = send_cldap_netlogon(sock, ads->config.realm, global_myname(), 6); if (ret != 0) { return ret; } ret = recv_cldap_netlogon(sock, &reply); close(sock); if (ret == -1) { return -1; } d_printf("Information for Domain Controller: %s\n\n", ads->config.ldap_server_name); d_printf("Response Type: "); switch (reply.type) { case SAMLOGON_AD_UNK_R: d_printf("SAMLOGON\n"); break; case SAMLOGON_AD_R: d_printf("SAMLOGON_USER\n"); break; default: d_printf("0x%x\n", reply.type); break; } d_printf("GUID: %s\n", smb_uuid_string_static(smb_uuid_unpack_static(reply.guid))); d_printf("Flags:\n" "\tIs a PDC: %s\n" "\tIs a GC of the forest: %s\n" "\tIs an LDAP server: %s\n" "\tSupports DS: %s\n" "\tIs running a KDC: %s\n" "\tIs running time services: %s\n" "\tIs the closest DC: %s\n" "\tIs writable: %s\n" "\tHas a hardware clock: %s\n" "\tIs a non-domain NC serviced by LDAP server: %s\n", (reply.flags & ADS_PDC) ? "yes" : "no", (reply.flags & ADS_GC) ? "yes" : "no", (reply.flags & ADS_LDAP) ? "yes" : "no", (reply.flags & ADS_DS) ? "yes" : "no", (reply.flags & ADS_KDC) ? "yes" : "no", (reply.flags & ADS_TIMESERV) ? "yes" : "no", (reply.flags & ADS_CLOSEST) ? "yes" : "no", (reply.flags & ADS_WRITABLE) ? "yes" : "no", (reply.flags & ADS_GOOD_TIMESERV) ? "yes" : "no", (reply.flags & ADS_NDNC) ? "yes" : "no"); printf("Forest:\t\t\t%s\n", reply.forest); printf("Domain:\t\t\t%s\n", reply.domain); printf("Domain Controller:\t%s\n", reply.hostname); printf("Pre-Win2k Domain:\t%s\n", reply.netbios_domain); printf("Pre-Win2k Hostname:\t%s\n", reply.netbios_hostname); if (*reply.unk) printf("Unk:\t\t\t%s\n", reply.unk); if (*reply.user_name) printf("User name:\t%s\n", reply.user_name); printf("Site Name:\t\t%s\n", reply.site_name); printf("Site Name (2):\t\t%s\n", reply.site_name_2); d_printf("NT Version: %d\n", reply.version); d_printf("LMNT Token: %.2x\n", reply.lmnt_token); d_printf("LM20 Token: %.2x\n", reply.lm20_token); return ret; }
void ares__send_query(ares_channel channel, struct query *query, time_t now) { struct send_request *sendreq; struct server_state *server; server = &channel->servers[query->server]; if (query->using_tcp) { int tryWrite = 0; /* Make sure the TCP socket for this server is set up and queue * a send request. */ if (server->tcp_socket == -1) { if (open_tcp_socket(channel, server) == -1) { query->skip_server[query->server] = 1; next_server(channel, query, now); return; } if ( channel->poll_cb_func ) { // printf("ares_send_q: pollopen tcp fd=%d\n", server->tcp_socket); (*(channel->poll_cb_func))( channel->poll_cb_data, channel, query->server, server->tcp_socket, ARES_POLLACTION_OPEN); } } sendreq = malloc(sizeof(struct send_request)); if (!sendreq) end_query(channel, query, ARES_ENOMEM, NULL, 0); sendreq->data = query->tcpbuf; sendreq->len = query->tcplen; sendreq->next = NULL; if (server->qtail) { server->qtail->next = sendreq; } else { server->qhead = sendreq; tryWrite = 1; } server->qtail = sendreq; query->timeout = 0; if ( tryWrite ) { #if 0 time_t now; time(&now); write_tcp_data(channel, query->server, now); /* XXX: the write code doesn't seem to handle EAGAIN properly! */ #else if ( channel->poll_cb_func ) (*(channel->poll_cb_func))( channel->poll_cb_data, channel, query->server, server->tcp_socket, ARES_POLLACTION_WRITEON); #endif } } else { if (server->udp_socket == -1) { if (open_udp_socket(channel, server) == -1) { //fprintf(stderr,"kennard:ares:send_query:open_udp failed\n"); query->skip_server[query->server] = 1; next_server(channel, query, now); return; } if ( channel->poll_cb_func ) { // printf("ares_send_q: pollopen udp fd=%d\n", server->udp_socket); (*(channel->poll_cb_func))( channel->poll_cb_data, channel, query->server, server->udp_socket, ARES_POLLACTION_OPEN); } } if (send(server->udp_socket, query->qbuf, query->qlen, 0) == -1) { //fprintf(stderr,"kennard:ares:send_query:send_udp failed\n"); query->skip_server[query->server] = 1; next_server(channel, query, now); return; } query->timeout = now + ((query->itry == 0) ? channel->timeout : channel->timeout << query->itry / channel->nservers); } }
int $UPROTO$_server_proc(void *param) { int ret; unsigned int len; int port; char *first, *second, *third; char cnt_str[30]; pj_sockaddr_in caddr; char *caddr_str; pj_time_val timeout; pj_fd_set_t read_fds; char buffer[USERVER_BUFSIZE]; $UPROTO$_request_t request; $UPROTO$_server_t *userver = ($UPROTO$_server_t *)param; ansi_copy_str(cnt_str, userver->connect_str); first = cnt_str; second = strchr(first, ':'); EXIT_IF_TRUE(second == NULL, "Wrong connection string format\n"); *second = '\0'; second++; if(0 == strcmp(first, "udp")) { third = strchr(second, ':'); EXIT_IF_TRUE(third == NULL, "Wrong connection string format\n"); *third = '\0'; third++; port = atoi(third); open_udp_socket(userver, second, port); if (userver->on_open_socket_f != NULL) userver->on_open_socket_f(userver); userver->recv_f = &udp_recvfrom; userver->send_f = &udp_sendto; } else if( 0 == strcmp(first, "tty") ) { open_tty(userver, second); userver->recv_f = &tty_recvfrom; userver->send_f = &tty_sendto; } else { EXIT_IF_TRUE(1, "Unsuported protocol\n"); } // thread loop timeout.sec = 0; timeout.msec = 100; userver->is_end = 0; while( !userver->is_end ) { while (!userver->is_online) { SHOW_LOG(3, "Server is currently offline...\n"); //usleep(8*1000*1000); pj_thread_sleep(1000); } PJ_FD_ZERO(&read_fds); PJ_FD_SET(userver->fd, &read_fds); pj_mutex_lock(userver->mutex); ret = pj_sock_select(userver->fd + 1, &read_fds, NULL, NULL, &timeout); pj_mutex_unlock(userver->mutex); EXIT_IF_TRUE(ret < 0, "Error on server socket\n"); if( PJ_FD_ISSET(userver->fd, &read_fds) ) { len = sizeof(caddr); pj_bzero(&caddr, len); pj_mutex_lock(userver->mutex); ret = userver->recv_f(userver->fd, buffer, USERVER_BUFSIZE, (void *)&caddr, &len); pj_mutex_unlock(userver->mutex); caddr_str = pj_inet_ntoa(caddr.sin_addr); if( ret > 0 ) { buffer[ret] = '\0'; SHOW_LOG(5, "Received from client: %s\n", buffer); $UPROTO$_parse_request(buffer, ret, &request); userver->on_request_f(userver, &request, caddr_str); } } //usleep(100*1000); pj_thread_sleep(100); // if userver->fd is ready to write. When write finish, call userver->on_sent(); // else --> time out } return 0; }
int $UPROTO$_secure_server_proc(void *param) { int ret; unsigned int len; int port; char *first, *second, *third; char cnt_str[30]; pj_sockaddr_in caddr; char *caddr_str; pj_time_val timeout; pj_fd_set_t read_fds; char buffer[USERVER_BUFSIZE]; $UPROTO$_request_t request; // For lvc parsing lvc_t lvc; int len1; char *val; uint32_t *ts; char sts[32]; char plain[USERVER_BUFSIZE]; char *pph; char otp[32]; pj_str_t pjstr; // End for lvc parsing $UPROTO$_server_t *userver = ($UPROTO$_server_t *)param; ansi_copy_str(cnt_str, userver->connect_str); first = cnt_str; second = strchr(first, ':'); EXIT_IF_TRUE(second == NULL, "Wrong connection string format\n"); *second = '\0'; second++; if(0 == strcmp(first, "udp")) { third = strchr(second, ':'); EXIT_IF_TRUE(third == NULL, "Wrong connection string format\n"); *third = '\0'; third++; port = atoi(third); open_udp_socket(userver, second, port); if (userver->on_open_socket_f != NULL) userver->on_open_socket_f(userver); userver->recv_f = &udp_recvfrom; userver->send_f = &udp_sendto; } else if( 0 == strcmp(first, "tty") ) { open_tty(userver, second); userver->recv_f = &tty_recvfrom; userver->send_f = &tty_sendto; } else { EXIT_IF_TRUE(1, "Unsuported protocol\n"); } // thread loop timeout.sec = 0; timeout.msec = 100; userver->is_end = 0; while( !userver->is_end ) { while (!userver->is_online) { SHOW_LOG(3, "Server is currently offline...\n"); pj_thread_sleep(1000); } PJ_FD_ZERO(&read_fds); PJ_FD_SET(userver->fd, &read_fds); pj_mutex_lock(userver->mutex); ret = pj_sock_select(userver->fd + 1, &read_fds, NULL, NULL, &timeout); pj_mutex_unlock(userver->mutex); EXIT_IF_TRUE(ret < 0, "Error on server socket\n"); if( PJ_FD_ISSET(userver->fd, &read_fds) ) { len = sizeof(caddr); pj_bzero(&caddr, len); pj_mutex_lock(userver->mutex); ret = userver->recv_f(userver->fd, buffer, USERVER_BUFSIZE, (void *)&caddr, &len); pj_mutex_unlock(userver->mutex); caddr_str = pj_inet_ntoa(caddr.sin_addr); if( ret > 0 ) { buffer[ret] = '\0'; lvc_init(&lvc, buffer, ret); lvc_unpack(&lvc, &len, &val); pj_strset(&pjstr, val, len); pph = userver->get_pph_f(&pjstr); if( pph != NULL ) { lvc_unpack(&lvc, &len, &val); ts = (uint32_t *)val; ts2str(*ts, sts); lvc_unpack(&lvc, &len, &val); generate_otp(otp, pph, sts); do_decrypt(val, len, plain, &len1, otp); if( pj_ansi_strncmp(sts, plain, len1) == 0 ) { lvc_unpack(&lvc, &len, &val); do_decrypt(val, len, plain, &len1, otp); plain[len1] = '\0'; $UPROTO$_parse_request(plain, len1, &request); userver->on_request_f(userver, &request, caddr_str); } } //else { //} } } pj_thread_sleep(100); } return 0; }
int main(int argc, char** argv) { int target = TARGET_UDP_SOCKET; int input = INPUT_FILE; int output_mode = OUTPUT_MODE_CLICK; filter_code = 0xFF; filter_rate = 0xFFFF; filter_Nrx = 0xFF; char *csi_node = "0.0.0.0"; char *tx_node = "0.0.0.1"; int debug_level = 0; if ( (argc < 5) || ((argc > 1) && (strcmp(argv[1], "help") == 0)) ) { print_help(); exit(0); } target = io_type(argv[1][2],TARGET); input = io_type(argv[1][0],INPUT); output_mode = format_type(argv[4][0]); printf("Config: %s (%s -> %s) %s %s %s\n", argv[1], input_types[input], output_types[target], argv[2], argv[3], format_types[output_mode]); if ( argc > 5 ) { csi_node = argv[5]; tx_node = argv[6]; } if ( argc > 7 ) { debug_level = atoi(argv[7]); } struct cn_msg *cmsg; unsigned char cmsg_input_buf[BUF_SIZE]; char sendline[3000]; unsigned char buf[BUF_SIZE]; int ret; int count = 0; char hostname[1024]; gethostname(hostname, 1024); uint32_t csi_node_addr = (uint32_t)inet_addr(csi_node); uint32_t tx_node_addr = (uint32_t)inet_addr(tx_node); unsigned short l, l2; /* Make sure usage is correct */ check_usage(argc, argv); /* Set up the "caught_signal" function as this program's sig handler */ signal(SIGINT, caught_signal); /* Prepare Input */ switch ( input ) { case INPUT_SOCKET: netlink_sock_fd = open_iwl_netlink_socket(); break; case INPUT_FILE: netlink_sock_fd = open_file(argv[3], "r"); break; } /* Prepare Output */ switch ( target ) { case TARGET_TCP_SOCKET: out_fd = open_tcp_socket(argv[2], 32000); break; case TARGET_UDP_SOCKET: out_fd = open_udp_socket(argv[2], 32000); break; case TARGET_FILE: out_fd = open_file(argv[2], "w"); break; case TARGET_STDOUT: out_fd = 1; break; } /* Poll socket forever waiting for a message */ u_char *buf_p; int len_p, len_sendline; while (1) { /* Receive from socket with infinite timeout */ //ret = recv(sock_fd, buf, sizeof(buf), 0); /* Read the next entry size */ if (DEBUG_LEVEL_DEV) { printf("\n----- Next Data -----\n\n"); } switch (input) { case INPUT_FILE: /* Read the next entry size */ ret = read(netlink_sock_fd, &l2, 1 * sizeof(unsigned short)); if ( ret != 0 ) { l = ntohs(l2); /* Sanity-check the entry size */ if (l == 0) { fprintf(stderr, "Error: got entry size=0\n"); exit_program(-1); } else if (l > BUF_SIZE) { fprintf(stderr, "Error: got entry size %u > BUF_SIZE=%u\n", l, BUF_SIZE); exit_program(-2); } /* Read in the entry */ read(netlink_sock_fd, buf, l * sizeof(*buf)); cmsg = (struct cn_msg*)&cmsg_input_buf[0]; cmsg->id.idx = 0; cmsg->id.val = 0; cmsg->seq = 0; cmsg->ack = 0; cmsg->len = l; cmsg->flags = 0; memcpy(cmsg->data,buf,l); } if ( ret == 0 ) ret = -1; break; case INPUT_SOCKET: ret = iwl_netlink_recv(netlink_sock_fd, &buf_p, &len_p, &cmsg); break; } if (ret == -1) exit_program_err(-1, "recv"); if (cmsg == NULL) { printf("cmsg == NULL\n"); continue; } struct iwl5000_bfee_notif *bfee = NULL; bfee = (struct iwl5000_bfee_notif *)&(cmsg->data[1]); /* Filter */ if ( (filter_code != 0xFF) && (cmsg->data[0] != filter_code) ) continue; if ( (filter_rate != 0xFFFF) && (bfee->fake_rate_n_flags != filter_rate) ) continue; if ( (filter_Nrx != 0xFF) && (bfee->Nrx != filter_Nrx) ) continue; if (DEBUG_LEVEL_DEV) printf("Entry size=%d, code=0x%X\n", cmsg->len, cmsg->data[0]); /* Evaluation */ double eff_snrs[MAX_NUM_RATES][4]; if ( cmsg->data[0] == IWL_CONN_BFEE_NOTIF /*0xBB*/) { /* Beamforming packet */ calc_eff_snrs(bfee, eff_snrs); struct timeval timeVal; gettimeofday (&timeVal, NULL); if (DEBUG_LEVEL_INFO) printf("Rcvd pkt at <%ld.%06ld>\n", (long int)(timeVal.tv_sec), (long int)(timeVal.tv_usec)); if (DEBUG_LEVEL_DEV) { /* Beamforming packet */ printf("\nBeamforming: rate=0x%x\n", bfee->fake_rate_n_flags); /* Pull out the message portion and print some stats */ if (count % SLOW_MSG_CNT == 0) printf("Received %d bytes: id: %d val: %d seq: %d clen: %d\n", cmsg->len, cmsg->id.idx, cmsg->id.val, cmsg->seq, cmsg->len); printf("\n--- Effektive SNR ---\n\n"); int i; for ( i = 0; i < MAX_NUM_RATES; i++) { printf("%d: %f %f %f %f\n", i, db(eff_snrs[i][0]), db(eff_snrs[i][1]), db(eff_snrs[i][2]), db(eff_snrs[i][3])); } printf("\n---------------------\n\n"); } } /* Log the data remote */ /* Puffer mit Text füllen */ switch (output_mode) { case OUTPUT_MODE_FORMAT: sprintf(sendline, "%s, Received %d bytes: id: %d val: %d seq: %d clen: %d\n", hostname, cmsg->len, cmsg->id.idx, cmsg->id.val, cmsg->seq, cmsg->len); len_sendline = strlen(sendline); break; case OUTPUT_MODE_BFEE: if ( bfee != NULL) { calc_eff_snrs_tostr(bfee, eff_snrs, sendline, hostname); } else { sprintf(sendline, "bfee == NULL\n"); } if (DEBUG_LEVEL_DEV) printf("To tx:\n%s\n", sendline); break; case OUTPUT_MODE_CLICK: len_sendline = click_output(sendline, bfee, cmsg, eff_snrs, csi_node_addr, tx_node_addr); break; default: /* Log the data to file */ l = (unsigned short) cmsg->len; l2 = htons(l); memcpy(sendline, &l2, 1 * sizeof(unsigned short)); len_sendline = 1 * sizeof(unsigned short); memcpy(&(sendline[len_sendline]), cmsg->data, 1 * l); len_sendline += 1 * l; if ((count % 100 == 0) && (DEBUG_LEVEL_DEV)) printf("wrote %d bytes [msgcnt=%u]\n", len_sendline, count); } switch ( target ) { case TARGET_FILE: case TARGET_TCP_SOCKET: ret = write(out_fd, sendline, len_sendline); break; case TARGET_UDP_SOCKET: sendto(out_fd, sendline, len_sendline, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); break; case TARGET_STDOUT: dprintf(out_fd,"%s",sendline); break; } ++count; } exit_program(0); return 0; }
static void *run(void * _args) { // Cast _args struct guppi_thread_args *args = (struct guppi_thread_args *)_args; THREAD_RUN_BEGIN(args); THREAD_RUN_SET_AFFINITY_PRIORITY(args); THREAD_RUN_ATTACH_STATUS(args->instance_id, st); // Attach to paper_ouput_databuf THREAD_RUN_ATTACH_DATABUF(args->instance_id, paper_output_databuf, db, args->input_buffer); // Setup socket and message structures int sockfd; unsigned int xengine_id = 0; struct timespec packet_delay = { .tv_sec = 0, .tv_nsec = PACKET_DELAY_NS }; guppi_status_lock_safe(&st); hgetu4(st.buf, "XID", &xengine_id); // No change if not found hputu4(st.buf, "XID", xengine_id); hputu4(st.buf, "OUTDUMPS", 0); guppi_status_unlock_safe(&st); pkt_t pkt; pkt.hdr.header = HEADER; pkt.hdr.instids = INSTIDS(xengine_id); pkt.hdr.pktinfo = PKTINFO(BYTES_PER_PACKET); pkt.hdr.heaplen = HEAPLEN; // TODO Get catcher hostname and port from somewhere #ifndef CATCHER_PORT #define CATCHER_PORT 7148 #endif #define stringify2(x) #x #define stringify(x) stringify2(x) // Open socket sockfd = open_udp_socket("catcher", stringify(CATCHER_PORT)); if(sockfd == -1) { guppi_error(__FUNCTION__, "error opening socket"); run_threads=0; pthread_exit(NULL); } #ifdef TEST_INDEX_CALCS int i, j; for(i=0; i<32; i++) { for(j=i; j<32; j++) { regtile_index(2*i, 2*j); } } for(i=0; i<32; i++) { for(j=i; j<32; j++) { casper_index(2*i, 2*j); } } run_threads=0; #endif /* Main loop */ int rv; int casper_chan, gpu_chan; int baseline; unsigned int dumps = 0; int block_idx = 0; struct timespec start, stop; signal(SIGINT,cc); signal(SIGTERM,cc); while (run_threads) { guppi_status_lock_safe(&st); hputs(st.buf, STATUS_KEY, "waiting"); guppi_status_unlock_safe(&st); // Wait for new block to be filled while ((rv=paper_output_databuf_wait_filled(db, block_idx)) != GUPPI_OK) { if (rv==GUPPI_TIMEOUT) { guppi_status_lock_safe(&st); hputs(st.buf, STATUS_KEY, "blocked"); guppi_status_unlock_safe(&st); continue; } else { guppi_error(__FUNCTION__, "error waiting for filled databuf"); run_threads=0; pthread_exit(NULL); break; } } clock_gettime(CLOCK_MONOTONIC, &start); // Note processing status, current input block guppi_status_lock_safe(&st); hputs(st.buf, STATUS_KEY, "processing"); hputi4(st.buf, "OUTBLKIN", block_idx); guppi_status_unlock_safe(&st); // Update header's timestamp for this dump pkt.hdr.timestamp = TIMESTAMP(db->block[block_idx].header.mcnt * N_TIME_PER_PACKET * 2 * N_CHAN_TOTAL / 128); // Init header's offset for this dump uint32_t nbytes = 0; pkt.hdr.offset = OFFSET(nbytes); // Unpack and convert in packet sized chunks float * pf_re = db->block[block_idx].data; float * pf_im = db->block[block_idx].data + xgpu_info.matLength; pktdata_t * p_out = pkt.data; for(casper_chan=0; casper_chan<N_CHAN_PER_X; casper_chan++) { // De-interleave the channels gpu_chan = (casper_chan/Nc) + ((casper_chan%Nc)*Nx); for(baseline=0; baseline<CASPER_CHAN_LENGTH; baseline++) { off_t idx_regtile = idx_map[baseline]; pktdata_t re = CONVERT(pf_re[gpu_chan*REGTILE_CHAN_LENGTH+idx_regtile]); pktdata_t im = CONVERT(pf_im[gpu_chan*REGTILE_CHAN_LENGTH+idx_regtile]); *p_out++ = re; *p_out++ = -im; // Conjugate data to match downstream expectations nbytes += 2*sizeof(pktdata_t); if(nbytes % BYTES_PER_PACKET == 0) { int bytes_sent = send(sockfd, &pkt, sizeof(pkt.hdr)+BYTES_PER_PACKET, 0); if(bytes_sent == -1) { // Send all packets even if cactcher is not listening (i.e. we // we get a connection refused error), but abort sending this // dump if we get any other error. if(errno != ECONNREFUSED) { perror("send"); // Update stats guppi_status_lock_safe(&st); hputu4(st.buf, "OUTDUMPS", ++dumps); hputr4(st.buf, "OUTSECS", 0.0); hputr4(st.buf, "OUTMBPS", 0.0); guppi_status_unlock_safe(&st); // Break out of both for loops goto done_sending; } } else if(bytes_sent != sizeof(pkt.hdr)+BYTES_PER_PACKET) { printf("only sent %d of %lu bytes!!!\n", bytes_sent, sizeof(pkt.hdr)+BYTES_PER_PACKET); } // Delay to prevent overflowing network TX queue nanosleep(&packet_delay, NULL); // Setup for next packet p_out = pkt.data; // Update header's byte_offset for this chunk pkt.hdr.offset = OFFSET(nbytes); } } } clock_gettime(CLOCK_MONOTONIC, &stop); guppi_status_lock_safe(&st); hputu4(st.buf, "OUTDUMPS", ++dumps); hputr4(st.buf, "OUTSECS", (float)ELAPSED_NS(start,stop)/1e9); hputr4(st.buf, "OUTMBPS", (1e3*8*bytes_per_dump)/ELAPSED_NS(start,stop)); guppi_status_unlock_safe(&st); done_sending: // Mark block as free paper_output_databuf_set_free(db, block_idx); // Setup for next block block_idx = (block_idx + 1) % db->header.n_block; /* Will exit if thread has been cancelled */ pthread_testcancel(); } // Have to close all pushes THREAD_RUN_DETACH_DATAUF; THREAD_RUN_DETACH_STATUS; THREAD_RUN_END; // Thread success! return NULL; } static pipeline_thread_module_t module = { name: "paper_gpu_output_thread", type: PIPELINE_OUTPUT_THREAD, init: init, run: run };