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

📄 dhcp-eth.c

📁 this is sample about DHCP-agent
💻 C
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-eth.c,v 1.4 2002/12/27 02:53:45 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. * *  * Ethernet object. *  */#define MODULE_NAME "dhcp-eth"#include "dhcp-local.h"#include "dhcp-libutil.h"#include "dhcp-librawnet.h"#include "dhcp-align.h"eth_obj *eth_create(void){    eth_obj *eth;    eth = xmalloc(sizeof(eth_obj));    return eth;}void eth_destroy(eth_obj * eth){    xfree(eth);    return;}eth_addr_t eth_get_src_addr(eth_obj * eth){    return (eth->header.eth_src);}eth_addr_t eth_get_dst_addr(eth_obj * eth){    return (eth->header.eth_dst);}uint16_t eth_get_type(eth_obj * eth){    return (ntohs(eth->header.eth_type));}void eth_set_src_addr(eth_obj * eth, eth_addr_t addr){    memcpy(&eth->header.eth_src.data, &addr.data, ETH_ADDR_LEN);    return;}void eth_set_dst_addr(eth_obj * eth, eth_addr_t addr){    memcpy(&eth->header.eth_dst.data, &addr.data, ETH_ADDR_LEN);    return;}void eth_set_type(eth_obj * eth, uint16_t type){    eth->header.eth_type = htons(type);    return;}int eth_read_packet_image(eth_obj * eth, const unsigned char *packet, int len){    if(len < ETH_HDR_LEN)        return -1;    align_eth(packet, &eth->header);    return 0;}void eth_write_packet_image(eth_obj * eth, unsigned char *packet){    /* Structures may have padding     * so copy out each member individually. */    memcpy(packet, &eth->header.eth_dst.data, ETH_ADDR_LEN);    packet += ETH_ADDR_LEN;    memcpy(packet, &eth->header.eth_src.data, ETH_ADDR_LEN);    packet += ETH_ADDR_LEN;    memcpy(packet, &eth->header.eth_type, 2);    return;}

⌨️ 快捷键说明

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