1 /* 2 * Copyright (C) 2013 4th Line GmbH, Switzerland 3 * 4 * The contents of this file are subject to the terms of either the GNU 5 * Lesser General Public License Version 2 or later ("LGPL") or the 6 * Common Development and Distribution License Version 1 or later 7 * ("CDDL") (collectively, the "License"). You may not use this file 8 * except in compliance with the License. See LICENSE.txt for more 9 * information. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 */ 15 16 package org.fourthline.cling.model.message; 17 18 import java.net.InetAddress; 19 20 /** 21 * A received UDP datagram request or response message, with source address and port. 22 * <p> 23 * Additionally, holds a local address that is reachable from the source 24 * address (in the same subnet): 25 * </p> 26 * <ul> 27 * <li>When an M-SEARCH is received, we send a LOCATION header back with a 28 * reachable (by the remote control point) local address.</li> 29 * <li>When a NOTIFY discovery message (can be a search response) is received we 30 need to memorize on which local address it was received, so that the we can 31 later give the remote device a reachable (from its point of view) local 32 GENA callback address.</li> 33 * </ul> 34 * 35 * @author Christian Bauer 36 */ 37 public class IncomingDatagramMessage<O extends UpnpOperation> extends UpnpMessage<O> { 38 39 private InetAddress sourceAddress; 40 private int sourcePort; 41 private InetAddress localAddress; 42 43 public IncomingDatagramMessage(O operation, InetAddress sourceAddress, int sourcePort, InetAddress localAddress) { 44 super(operation); 45 this.sourceAddress = sourceAddress; 46 this.sourcePort = sourcePort; 47 this.localAddress = localAddress; 48 } 49 50 protected IncomingDatagramMessage(IncomingDatagramMessage<O> source) { 51 super(source); 52 this.sourceAddress = source.getSourceAddress(); 53 this.sourcePort = source.getSourcePort(); 54 this.localAddress = source.getLocalAddress(); 55 } 56 57 public InetAddress getSourceAddress() { 58 return sourceAddress; 59 } 60 61 public int getSourcePort() { 62 return sourcePort; 63 } 64 65 public InetAddress getLocalAddress() { 66 return localAddress; 67 } 68 69 }