📄 slpfunc.c
字号:
/* * Embedded SLP Message Functions * * ./software/ch10/emslp/slpfunc.c * * mtj@cogitollc.com * */#include <stdio.h>#include <string.h>#include <ctype.h>#include "manip.h"#include "slppriv.h"#define SLP_VERSION 2/* * slpCreateHeader() * * Populate an SLP message header with default and user-defined values. * */void slpCreateHeader( slpMsgType *slpMsg, int type, const char *lang, uint8_t flags ){ int len = strlen(lang); extern int archType; if ((slpMsg == NULL) || (lang == NULL)) return; bzero( (void *)slpMsg, sizeof(slpMsgType) ); if (archType == MULTICAST_ARCH) flags |= REQUEST_MCAST; emitByte(slpMsg, SLP_VERSION); emitByte(slpMsg, (unsigned char)type); emitShort(slpMsg, 0); emitByte(slpMsg, 0); // Fake length emitByte(slpMsg, flags); emitShort(slpMsg, 0); // Rsvd / Next Ext Offset emitShort(slpMsg, 0); // Next Offset Continued emitShort(slpMsg, 0); // Fake XID emitShort(slpMsg, len); // Language Tag Length emitString(slpMsg, lang); // Language Tag}/* * setSlpHeaderLength() * * Set the length of an SLP message in the SLP header. * */void setSlpHeaderLength( slpMsgType *slpMsg ){ if (slpMsg == NULL) return; /* Load the message length into the slp message buffer */ slpMsg->buffer[2] = (unsigned char)((slpMsg->len >> 16) & 0xff); slpMsg->buffer[3] = (unsigned char)((slpMsg->len >> 8) & 0xff); slpMsg->buffer[4] = (unsigned char)((slpMsg->len) & 0xff);}/* * setSlpXID() * * Set the XID of an SLP message in the SLP header. * */void setSlpXID( slpMsgType *slpMsg, uint16_t xid ){ if (slpMsg == NULL) return; slpMsg->buffer[10] = (unsigned char)((xid >> 8) & 0xff); slpMsg->buffer[11] = (unsigned char)((xid) & 0xff);}/* * slpPrintMessage() * * Debug function to emit an SLP message. * */void slpPrintMessage( slpMsgType *slpMsg ){#ifdef SLP_DEBUG int i, j, start=0; if (slpMsg == NULL) return; for (i = 0 ; i < slpMsg->len ; i++) { if ((i % 16) == 0) { if (i != 0) { start = i-16; printf(" "); for (j = start ; j < i ; j++) { printf("%c", (isprint(slpMsg->buffer[j]) ? slpMsg->buffer[j] : '.')); } } printf("\n %04x : ", i); } printf("%02x ", (unsigned char)slpMsg->buffer[i]); } if ((i % 16) != 0) { for (j = 0 ; j < (16 - (i % 16)) ; j++) { printf(" "); } printf(" "); for (j = start+16 ; j < i ; j++) { printf("%c", (isprint(slpMsg->buffer[j]) ? slpMsg->buffer[j] : '.')); } } printf("\n");#endif return;}/* * Copyright (c) 2002 Charles River Media. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee 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. Neither the name of Charles River Media nor the names of * its contributors may be used to endorse or promote products * derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY CHARLES RIVER MEDIA AND CONTRIBUTERS * 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CHARLES * RIVER MEDIA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARAY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -