⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcp-udp.c

📁 this is sample about DHCP-agent
💻 C
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-udp.c,v 1.3 2002/11/16 00:23:44 actmodern Exp $ * Copyright 2002 Thamer Alharbash <tmh@whitefang.com> *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *  */#define MODULE_NAME "dhcp-udp"#include "dhcp-local.h"#include "dhcp-libutil.h"#include "dhcp-librawnet.h"#include "dhcp-align.h"udp_obj *udp_create(void){    udp_obj *udp;    udp = xmalloc(sizeof(udp_obj));    return udp;}void udp_destroy(udp_obj * udp){    xfree(udp);    return;}int udp_read_packet_image(udp_obj * udp, const unsigned char *packet, int len){    if(len < UDP_HDR_LEN)        return -1;    align_udp(packet, &udp->header);    return 0;}/* get routines. */uint16_t udp_get_src_port(udp_obj * udp){    return ntohs(udp->header.uh_sport);}uint16_t udp_get_dst_port(udp_obj * udp){    return ntohs(udp->header.uh_dport);}uint16_t udp_get_len(udp_obj * udp){    return ntohs(udp->header.uh_ulen);}/* set routines. */void udp_set_src_port(udp_obj * udp, uint16_t src_port){    udp->header.uh_sport = htons(src_port);    return;}void udp_set_dst_port(udp_obj * udp, uint16_t dst_port){    udp->header.uh_dport = htons(dst_port);    return;}void udp_set_len(udp_obj * udp, uint16_t len){    udp->header.uh_ulen = htons(len);    return;}void udp_set_cksum(udp_obj * udp, uint16_t cksum){    udp->header.uh_sum = htons(cksum);    return;}void udp_write_packet_image(udp_obj * udp, unsigned char *packet){    memcpy(packet, &udp->header.uh_sport, 2);    packet += 2;    memcpy(packet, &udp->header.uh_dport, 2);    packet += 2;    memcpy(packet, &udp->header.uh_ulen, 2);    packet += 2;    memcpy(packet, &udp->header.uh_sum, 2);    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -