X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/3899282dbba9860e0cc121ea698a82217bed78ca..29895f4c7abb19a67b0ede58ae4f7d403023e171:/projects/stargazer/plugins/capture/cap_debug/udp.c diff --git a/projects/stargazer/plugins/capture/cap_debug/udp.c b/projects/stargazer/plugins/capture/cap_debug/udp.c deleted file mode 100644 index 238c95db..00000000 --- a/projects/stargazer/plugins/capture/cap_debug/udp.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $Id: udp.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $ - -Copyright (C) 2002 Marc Kirchner - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "libpal.h" -#include "types.h" - -int -pkt_udp_header(struct packet *pkt, unsigned short int sport, unsigned short int dport, unsigned short int udp_total_len, unsigned short int checksum) -{ - struct udphdr *udp; - - if (!pkt) - return EPKTINVALPTR; - if (pkt->pkt_size >= (pkt->pkt_pos + sizeof(struct udphdr))) { - udp = (struct udphdr *) pkt->pkt_ptr; - udp->source = htons(sport); - udp->dest = htons(dport); - udp->len = htons(udp_total_len); - udp->check = htons(checksum); - return 0; - } else - return EPKTRANGE; -} - -int -pkt_udp_cksum(struct packet *pkt, char *saddr, char *daddr, - unsigned int udp_total_len) -{ - char *tosum; - struct pseudohdr *psh; - struct udphdr *udp; - unsigned short int check=0; - struct in_addr addr; - - if (!pkt || !saddr || !daddr) - return EPKTINVALPTR; - - if ((udp_total_len + pkt->pkt_pos) > pkt->pkt_size -1) - return EPKTRANGE; - - if ((tosum = (char *) malloc(udp_total_len+sizeof(struct pseudohdr))) != NULL) { - memset(tosum, 0, udp_total_len+sizeof(struct pseudohdr)); - psh = (struct pseudohdr *) tosum; - udp = (struct udphdr *) pkt->pkt_ptr; - - udp->check = 0; - - if (inet_pton(AF_INET, saddr, &addr) < 0) - return EERRNO; - psh->saddr = addr.s_addr; - if (inet_pton(AF_INET, daddr, &addr) < 0) - return EERRNO; - psh->daddr = addr.s_addr; - psh->zero = 0x00; - psh->protocol = IPPROTO_UDP; - psh->length = htons(udp_total_len); - - memcpy(tosum + sizeof(struct pseudohdr), udp, udp_total_len); - check = in_cksum((unsigned short *)tosum, udp_total_len + sizeof(struct pseudohdr)); - /* _no_ call to htons(), because tosum is in network byte order */ - udp->check = check == 0 ? 0xffff : check; - free(tosum); - return 0; - } else - return EERRNO; -}