/*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
#define _NET_LACP_H_
#include <sys/types.h>
+#include <string.h>
/**
** Link Aggregation Control Protocol (LACP) definitions
return ((state & LACP_ACTOR_PARTNER_STATE_EXPIRED) != 0);
}
+/*
+ * Function: lacp_uint16_set
+ * Purpose:
+ * Set a field in a structure that's at least 16 bits to the given
+ * value, putting it into network byte order
+ */
+static __inline__ void
+lacp_uint16_set(uint8_t * field, uint16_t value)
+{
+ uint16_t tmp_value = htons(value);
+ memcpy((void *)field, (void *)&tmp_value, sizeof(uint16_t));
+ return;
+}
+
+/*
+ * Function: lacp_uint16_get
+ * Purpose:
+ * Get a field in a structure that's at least 16 bits, converting
+ * to host byte order.
+ */
+static __inline__ uint16_t
+lacp_uint16_get(const uint8_t * field)
+{
+ uint16_t tmp_field;
+ memcpy((void *)&tmp_field, (void *)field, sizeof(uint16_t));
+ return (ntohs(tmp_field));
+}
+
+/*
+ * Function: lacp_uint32_set
+ * Purpose:
+ * Set a field in a structure that's at least 32 bits to the given
+ * value, putting it into network byte order
+ */
+static __inline__ void
+lacp_uint32_set(uint8_t * field, uint32_t value)
+{
+ uint32_t tmp_value = htonl(value);
+ memcpy((void *)field, (void *)&tmp_value, sizeof(uint32_t));
+ return;
+}
+
+/*
+ * Function: lacp_uint32_get
+ * Purpose:
+ * Get a field in a structure that's at least 32 bits, converting
+ * to host byte order.
+ */
+static __inline__ uint32_t
+lacp_uint32_get(const uint8_t * field)
+{
+ uint32_t tmp_field;
+ memcpy((void *)&tmp_field, (void *)field, sizeof(uint32_t));
+ return (ntohl(tmp_field));
+}
/*
* LACP Actor/Partner TLV access functions
lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv,
lacp_system_priority system_priority)
{
- *((lacp_system_priority *)tlv->lap_system_priority)
- = (lacp_system_priority)htons(system_priority);
+ lacp_uint16_set(tlv->lap_system_priority, system_priority);
return;
}
static __inline__ lacp_system_priority
lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv)
{
- return ((lacp_system_priority)
- ntohs(*((u_short *)tlv->lap_system_priority)));
+ return (lacp_system_priority)lacp_uint16_get(tlv->lap_system_priority);
}
static __inline__ void
lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv, lacp_key key)
{
- *((lacp_key *)tlv->lap_key) = (lacp_key)htons(key);
+ lacp_uint16_set(tlv->lap_key, key);
return;
}
static __inline__ lacp_key
lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv)
{
- return ((lacp_key)ntohs(*((u_short *)tlv->lap_key)));
+ return (lacp_key)lacp_uint16_get(tlv->lap_key);
}
static __inline__ void
lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv,
lacp_port_priority port_priority)
{
- *((lacp_port_priority *)tlv->lap_port_priority)
- = (lacp_port_priority)htons(port_priority);
+ lacp_uint16_set(tlv->lap_port_priority, port_priority);
return;
}
static __inline__ lacp_port_priority
lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv)
{
- return ((lacp_port_priority)ntohs(*((u_short *)tlv->lap_port_priority)));
+ return (lacp_port_priority)lacp_uint16_get(tlv->lap_port_priority);
}
static __inline__ void
lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv, lacp_port port)
{
- *((lacp_port *)tlv->lap_port) = (lacp_port)htons(port);
+ lacp_uint16_set(tlv->lap_port, port);
return;
}
static __inline__ lacp_port
lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv)
{
- return ((lacp_port)ntohs(*((u_short *)tlv->lap_port)));
+ return (lacp_port)lacp_uint16_get(tlv->lap_port);
}
/*
lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv,
lacp_collector_max_delay delay)
{
- *((lacp_collector_max_delay *)tlv->lac_max_delay)
- = (lacp_collector_max_delay)htons(delay);
+ lacp_uint16_set(tlv->lac_max_delay, delay);
return;
}
static __inline__ lacp_collector_max_delay
lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv)
{
- return ((lacp_collector_max_delay)ntohs(*((u_short *)tlv->lac_max_delay)));
+ return (lacp_collector_max_delay)lacp_uint16_get(tlv->lac_max_delay);
}
typedef struct lacpdu_s {
static __inline__ void
la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu, lacp_port port)
{
- *((lacp_port *)lmpdu->lm_requestor_port) = (lacp_port)htons(port);
+ lacp_uint16_set(lmpdu->lm_requestor_port, port);
return;
}
static __inline__ lacp_port
la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu)
{
- return ((lacp_port)ntohs(*((lacp_port *)lmpdu->lm_requestor_port)));
+ return (lacp_port)lacp_uint16_get(lmpdu->lm_requestor_port);
}
static __inline__ void
la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu,
la_marker_transaction_id xid)
{
- *((la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id)
- = (la_marker_transaction_id)htonl(xid);
+ lacp_uint32_set(lmpdu->lm_requestor_transaction_id, xid);
return;
}
static __inline__ la_marker_transaction_id
la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu)
{
- la_marker_transaction_id * xid_p;
-
- xid_p = (la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id;
- return ((la_marker_transaction_id)ntohl(*xid_p));
+ return (la_marker_transaction_id)lacp_uint32_get(lmpdu->lm_requestor_transaction_id);
}
static __inline__ void